X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 3607B4763A1 for ; Fri, 2 May 2003 18:33:23 -0400 (EDT) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by postgresql.org (Postfix) with ESMTP id 8AE83476128 for ; Fri, 2 May 2003 18:33:22 -0400 (EDT) Received: from [66.219.92.2] (HELO temoku) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3004215; Fri, 02 May 2003 15:33:13 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: "Katka a Daniel Dunajsky" , pgsql-sql@postgresql.org Subject: Re: How to increase precision? Date: Fri, 2 May 2003 15:32:45 -0700 User-Agent: KMail/1.4.3 References: In-Reply-To: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200305021532.45697.josh@agliodbs.com> X-Spam-Status: No, hits=-22.7 required=5.0 tests=BAYES_01,IN_REP_TO,REFERENCES,USER_AGENT_KMAIL autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200305/36 X-Sequence-Number: 13201 Hey Katka, > How to increase the precision of calculations in posgresql? >=20 > When I run this query: >=20 > select 5/2; >=20 > I get: >=20 > ?column? > -------- > 2 >=20 > It should be 2.5 shouldn't it? Nope! You're thinking like a normal person, not like a database engineer.= =20=20=20 Translated, here's what you told the database: Give me INTEGER 5 / INTEGER 2 and the database told you: INTEGER 2 if you'd asked, the database would also have happily told you: REMAINDER 1 What you really wanted to ask the database was: Give me NUMERIC 5 / NUMERIC 2 or in SQL: SELECT 5::NUMERIC/2::NUMERIC At which point you will get 2.5000 (NUMERIC) Look for a general book on SQL databases, which should be able to give you = a=20 primer on data types and casting. --=20 -Josh Berkus Aglio Database Solutions San Francisco