dbTalk Databases Forums  

Re: [BUGS] Precision and scale of numeric column reported as value

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss Re: [BUGS] Precision and scale of numeric column reported as value in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Oliver Jowett
 
Posts: n/a

Default Re: [BUGS] Precision and scale of numeric column reported as value - 03-23-2005 , 03:09 PM






Sergio Lob wrote:
Quote:
Bug to report - For a numeric in a table defined by:
CREATE TABLE SERG (F01NUM NUMERIC) ;
, the precision and scale reported by ResultSetMetaData.getScale() and
ResultSetMetaData.getPrecision() are value -1
What should they return instead in this case?

-O

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly


Reply With Quote
  #2  
Old   
Sergio Lob
 
Posts: n/a

Default Re: [BUGS] Precision and scale of numeric column reported as value - 03-23-2005 , 03:16 PM






Precision is the number of total digits in the number. Scale is the
number of fractional digits.
For instance, a column defined as NUMERIC(10,3) should return
precision=10, scale=3. The error only occurs for a column defined as
NUMERIC (without precision or scale specified). Presumably, there is a
default precision and scale assigned to the column by postgreSQL, which
is not -1.
Sergio

Oliver Jowett wrote:

Quote:
Sergio Lob wrote:

Bug to report - For a numeric in a table defined by:
CREATE TABLE SERG (F01NUM NUMERIC) ;
, the precision and scale reported by ResultSetMetaData.getScale() and
ResultSetMetaData.getPrecision() are value -1


What should they return instead in this case?

-O


---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match


Reply With Quote
  #3  
Old   
Alvaro Herrera
 
Posts: n/a

Default Re: [BUGS] Precision and scale of numeric column reported as value - 03-23-2005 , 03:28 PM



On Wed, Mar 23, 2005 at 04:13:22PM -0500, Sergio Lob wrote:
Quote:
Precision is the number of total digits in the number. Scale is the
number of fractional digits.
For instance, a column defined as NUMERIC(10,3) should return
precision=10, scale=3. The error only occurs for a column defined as
NUMERIC (without precision or scale specified). Presumably, there is a
default precision and scale assigned to the column by postgreSQL, which
is not -1.
That assumption is wrong. There is no default.

--
Alvaro Herrera (<alvherre[@]dcc.uchile.cl>)
"La primera ley de las demostraciones en vivo es: no trate de usar el sistema.
Escriba un guión que no toque nada para no causar daños." (Jakob Nielsen)

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


Reply With Quote
  #4  
Old   
Stephan Szabo
 
Posts: n/a

Default Re: [BUGS] Precision and scale of numeric column reported as value - 03-23-2005 , 03:31 PM




On Wed, 23 Mar 2005, Sergio Lob wrote:

Quote:
Precision is the number of total digits in the number. Scale is the
number of fractional digits.
For instance, a column defined as NUMERIC(10,3) should return
precision=10, scale=3. The error only occurs for a column defined as
NUMERIC (without precision or scale specified). Presumably, there is a
default precision and scale assigned to the column by postgreSQL, which
is not -1.
IIRC, there is not a default precision and scale assigned to the column.
It's treated as having an unspecified precision and scale.

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster


Reply With Quote
  #5  
Old   
Oliver Jowett
 
Posts: n/a

Default Re: [BUGS] Precision and scale of numeric column reported as value - 03-23-2005 , 03:46 PM



Sergio Lob wrote:
Quote:
Precision is the number of total digits in the number. Scale is the
number of fractional digits.
For instance, a column defined as NUMERIC(10,3) should return
precision=10, scale=3.
Yes, I understand that.

Quote:
The error only occurs for a column defined as
NUMERIC (without precision or scale specified). Presumably, there is a
default precision and scale assigned to the column by postgreSQL, which
is not -1.
There appears to be no default, which is why we currently return -1.

Scale should default to 0 per the standard, but defaults to whatever the
precision is in PostgreSQL (see the docs for details).

The docs claim an implementation precision limit of 1000, but that
doesn't seem to correspond to the actual implementation -- I can insert
and retrieve 2000 digits NUMERICs (for example) just fine. I can't see
an obvious limit on precision in the backend code. There may be a
theoretical limit somewhere around 2^30 digits, I think (limited by the
backend's memory allocation sanity checks), but I have not tested that.

Given that there is effectively no default, do you have suggestions for
a better value to return?

-O

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)


Reply With Quote
  #6  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] Precision and scale of numeric column reported as value - 03-23-2005 , 04:49 PM



Oliver Jowett <oliver (AT) opencloud (DOT) com> writes:
Quote:
There appears to be no default, which is why we currently return -1.
The spec's notion of a "default precision and scale" is that every
numeric column has a specific precision and scale --- ie, is physically
fixed-width --- and everything you store into it will be coerced to that
precision and scale. Postgres doesn't do it that way, which is why the
notion of a default is a bit meaningless.

Quote:
Scale should default to 0 per the standard, but defaults to whatever the
precision is in PostgreSQL (see the docs for details).
If you specify a precision only, we do assume scale 0 to go with it.
It's only the case of an unconstrained numeric column that we depart
from the spec for.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.