Thread: Dividing Money
Hey all, I have been trying to figure out how to divide a data field of type 'money'. And, I've been unsuccesful. So, I have a couple of questions to ask. When I query my database, using 'select price from item_money;', postgres returns just what I asked for.... (the first seven rows) price ------- $4.45 $2.95 $4.45 $2.95 $3.95 $3.95 $3.95 When I query my database using the query 'select price::float as price from item_money', I get back some wierd stuff.... (the first seven rows) price ---------- 1080319164 1080319108 1080319052 1080318996 1080318940 1080318884 1080318828 In my first query results, the first row is the same as the third row. And, the second row is the same as the fourth row. And, rows 5,6,7 are all the same. However, in the results returned from my second query, there are not any rows of equal value.... ??? Could someone explain this to me? Thanks in advance, Bob
>>>>> "BD" == Bob Dusek <bobd@palaver.net> writes: BD> When I query my database, using 'select price from item_money;', postgres BD> returns just what I asked for.... BD> (the first seven rows) BD> price BD> ------- BD> $4.45 BD> $2.95 BD> $4.45 BD> $2.95 BD> $3.95 BD> $3.95 BD> $3.95 BD> When I query my database using the query 'select price::float as price BD> from item_money', I get back some wierd stuff.... BD> (the first seven rows) BD> price BD> ---------- BD> 1080319164 BD> 1080319108 BD> 1080319052 BD> 1080318996 BD> 1080318940 BD> 1080318884 BD> 1080318828 BD> In my first query results, the first row is the same as the third row. BD> And, the second row is the same as the fourth row. And, rows 5,6,7 are BD> all the same. However, in the results returned from my second query, BD> there are not any rows of equal value.... ??? Pehaps these are _different_ sets of records? Try select oid, price from .... and select oid, price::float .... oid is unique identifyer of row. Try also use explicit order of records, '... order by price' or by any othe field. -- Anatoly K. Lasareff Email: tolik@icomm.ru Senior programmer
Hello Anatoly, mercoledì, 2 dicembre 98, you wrote: >>>>>> "BD" == Bob Dusek <bobd@palaver.net> writes: AKL> BD> When I query my database, using 'select price from item_money;', postgres AKL> BD> returns just what I asked for.... AKL> BD> (the first seven rows) AKL> BD> price AKL> BD> ------- AKL> BD> $4.45 AKL> BD> $2.95 AKL> BD> $4.45 AKL> BD> $2.95 AKL> BD> $3.95 AKL> BD> $3.95 AKL> BD> $3.95 AKL> BD> When I query my database using the query 'select price::float as price AKL> BD> from item_money', I get back some wierd stuff.... AKL> BD> (the first seven rows) AKL> BD> price AKL> BD> ---------- AKL> BD> 1080319164 AKL> BD> 1080319108 AKL> BD> 1080319052 AKL> BD> 1080318996 AKL> BD> 1080318940 AKL> BD> 1080318884 AKL> BD> 1080318828 AKL> BD> In my first query results, the first row is the same as the third row. AKL> BD> And, the second row is the same as the fourth row. And, rows 5,6,7 are AKL> BD> all the same. However, in the results returned from my second query, AKL> BD> there are not any rows of equal value.... ??? I don't know your PostgreSQL version but I suppose you have 6.3.2 or lower. There was a problem to cast money to float on such versions. v6.4 doesn't allow this kind of cast. prova=> select sal::float from emp; ERROR: No such function 'float8' with the specified attributes prova=> select sal::float from emp; -Jose'-