Re: Decimal ??

From: Jason Earl <jdearl(at)yahoo(dot)com>
To: Tubagus Nizomi <nizomi(at)dnet(dot)net(dot)id>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Decimal ??
Date: 2000-05-24 04:43:10
Message-ID: 20000524044310.7379.qmail@web111.yahoomail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

In PostgreSQL 7.0 (and I would bet 6.5) if you cast
either the numerator or the denominator as a numeric
then it does what you would expect.

For example:

insert into test (name, price) values ('Jason',
3::numeric/4);

OR

insert into test (name, price) values ('Earl',
3/4::numeric);

Will do what you want. Unfortunately:

insert into test (name, price) values ('Foobar',
(3/4)::numeric);

does _not_ do what you would expect. This (I imagine)
is because PostgreSQL sees the two values, assumes
they are integers and does integer division. Without
knowing exactly what you are trying to do (and what
language you are trying to do it in) it is hard to
guess if this is helpful, so write back if you need
more help.

Hopefully this is helpful.

Jason

--- Tubagus Nizomi <nizomi(at)dnet(dot)net(dot)id> wrote:
> I have table :
> create table test (name text, price numeric(6,2));
> CREATE
> insert into test values ('John',0.75);
> INSERT
>
> select * from test;
> name | price
> ---------
> John | 0.75
>
> but when i insert into test values ('John',3/4);
> INSERT
>
> select * from test;
> name | price
> ---------
> John | 0.00 ---> ???
>
> why this value 0.00 but i want to 0.75 ??? help me
> please.
>
> i am using mandrake 7 and postgres 6.5.3
>
> Thanks
> Nizomi

__________________________________________________
Do You Yahoo!?
Send instant messages & get email alerts with Yahoo! Messenger.
http://im.yahoo.com/

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2000-05-24 04:44:30 Re: Decimal ??
Previous Message Tubagus Nizomi 2000-05-24 02:55:51 Decimal ??