Re: [HACKERS] Problems on NUMERIC

From: "Thomas G(dot) Lockhart" <lockhart(at)alumni(dot)caltech(dot)edu>
To: Jan Wieck <jwieck(at)debis(dot)com>
Cc: PostgreSQL HACKERS <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: [HACKERS] Problems on NUMERIC
Date: 1998-12-22 14:59:18
Message-ID: 367FB3C6.35A67006@alumni.caltech.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> First I wonder why the can_coerce... stuff is #if'd out of
> parse_relation.c?

Oh! That looks like my style of #if FALSE, but I can't recall why it is
that way. Will look at it. Does it work to just substitute an #if TRUE?
Perhaps I had it disabled during debugging, but...

> How do other databases handle this problem. How is the
> precision of a numeric result defined?

I've enclosed some snippets from my SQL92 2nd Draft Standard doc. It
gives you a lot of latitude :)

- Tom

Syntax Rules

1) If the data type of both operands of a dyadic arithmetic opera-
tor is exact numeric, then the data type of the result is exact
numeric, with precision and scale determined as follows:

a) Let S1 and S2 be the scale of the first and second operands
respectively.

b) The precision of the result of addition and subtraction is
implementation-defined, and the scale is the maximum of S1
and S2.

c) The precision of the result of multiplication is implementation-
defined, and the scale is S1 + S2.

d) The precision and scale of the result of division is
implementation-defined.

<snip large amounts>

Whenever an exact or approximate numeric value is assigned to a
data item or parameter representing an exact numeric value, an
approximation of its value that preserves leading significant dig-
its after rounding or truncating is represented in the data type
of the target. The value is converted to have the precision and
scale of the target. The choice of whether to truncate or round is
implementation-defined.

An approximation obtained by truncation of a numerical value N
for an <exact numeric type> T is a value V representable in T such
that N is not closer to zero than the numerical value of V and such
that the absolute value of the difference between N and the numer-
ical value of V is less than the absolute value of the difference
between two successive numerical values representable in T.

An approximation obtained by rounding of a numerical value N for
an <exact numeric type> T is a value V representable in T such
that the absolute value of the difference between N and the nu-
merical value of V is not greater than half the absolute value
of the difference between two successive numerical values repre-
sentable in T. If there are more than one such values V, then it is
implementation-defined which one is taken.

All numerical values between the smallest and the largest value,
inclusive, representable in a given exact numeric type have an
approximation obtained by rounding or truncation for that type; it
is implementation-defined which other numerical values have such
approximations.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas G. Lockhart 1998-12-22 15:15:57 Re: [HACKERS] Problems on NUMERIC
Previous Message Michael Meskes 1998-12-22 13:20:10 ecpg patches