Re: Alternative to "Money" ...

From: Chris Gamache <cgg007(at)yahoo(dot)com>
To: Matt Clark <matt(at)ymogen(dot)net>, Harald Fuchs <hf118(at)protecting(dot)net>, pgsql-admin(at)postgresql(dot)org
Subject: Re: Alternative to "Money" ...
Date: 2004-02-03 16:08:13
Message-ID: 20040203160813.81708.qmail@web13808.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin


That does make more sense (cents? :) ).

View and rule still apply, tho. Better performance still?

create temporary table new_money (product text, cents int4);

create view v_new_money as select product, (cents::numeric/100)::numeric(10,2)
as dollars from new_money;

create rule v_new_money_upd as on update to v_new_money do instead update
new_money set product=new.product, cents=new.dollars * 100 where product =
old.product;

create rule v_new_money_del as on delete to v_new_money do instead delete from
new_money where product = old.product;

create rule v_new_money_ins as on insert to v_new_money do instead insert into
new_money (product, cents) values (new.product, new.dollars * 100);

insert into new_money (product, cents) values ('Flowbee','1995');
insert into new_money (product, cents) values ('Country Hits','995');
insert into v_new_money (product, dollars) values ('ThighMaster','39.95');
update v_new_money set dollars = '14.95' where product='Flowbee';

select * from v_new_money;
product | dollars
--------------+---------
Country Hits | 9.95
ThighMaster | 39.95
Flowbee | 14.95
(3 rows)

select * from new_money;
product | cents
--------------+-------
Country Hits | 995
ThighMaster | 3995
Flowbee | 1495
(3 rows)

CG

--- Matt Clark <matt(at)ymogen(dot)net> wrote:
> > .. I can't _quite_ tell if you're serious or not ... :)
> >
> > If you are serious, are you saying to do something like:
> >
> > CREATE TABLE new_money (product text, dollars int4, cents int4);
>
> Ha :-) That would not be serious. I'm pretty sure he meant to just store
> the product cost in cents instead of dollars, e.g.
>
> > CREATE TABLE new_money (product text, cents int4);
> > INSERT INTO new_money (product, cents) values ('Flowbee','1995');
> > INSERT INTO new_money (product, cents) values ('Garth Brooks\'s
> > Greatest Hits','999');
>
> M
>

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Harald Fuchs 2004-02-03 16:17:40 Re: Alternative to "Money" ...
Previous Message Tom Lane 2004-02-03 15:21:14 Re: pg_dump privileges