pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chris Gamache <cgg007@yahoo.com>
To: Matt Clark <matt@ymogen.net>
To: Harald Fuchs <hf118@protecting.net>
To: pgsql-admin@postgresql.org
Subject: Re: Alternative to "Money" ...
Date: Tue, 3 Feb 2004 08:08:13 -0800 (PST)
Message-ID: <20040203160813.81708.qmail@web13808.mail.yahoo.com> (raw)
In-Reply-To: <OAEAKHEHCMLBLIDGAFELAEECEJAA.matt@ymogen.net>


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@ymogen.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/



view thread (10+ messages)  latest in thread

Message-ID: <20040203160813.81708.qmail@web13808.mail.yahoo.com>
Permalink:  ../20040203160813.81708.qmail@web13808.mail.yahoo.com/
Also on:    postgresql.org/message-id/20040203160813.81708.qmail@web13808.mail.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: cgg007@yahoo.com, matt@ymogen.net, hf118@protecting.net
  Subject: Re: Alternative to "Money" ...
  In-Reply-To: <20040203160813.81708.qmail@web13808.mail.yahoo.com>
  References: <OAEAKHEHCMLBLIDGAFELAEECEJAA.matt@ymogen.net> <20040203160813.81708.qmail@web13808.mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox