Re: pg_typeof equivalent for numeric scale, numeric/timestamp precision? - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: pg_typeof equivalent for numeric scale, numeric/timestamp precision?
Date
Msg-id 20121002215027.GF11163@svana.org
Whole thread Raw
In response to pg_typeof equivalent for numeric scale, numeric/timestamp precision?  (Craig Ringer <ringerc@ringerc.id.au>)
Responses Re: pg_typeof equivalent for numeric scale, numeric/timestamp precision?  (Craig Ringer <ringerc@ringerc.id.au>)
List pgsql-general
On Tue, Oct 02, 2012 at 10:19:18AM +0800, Craig Ringer wrote:
> Hi all
>
> While examining a reported issue with the JDBC driver I'm finding
> myself wanting SQL-level functions to get the scale and precision of
> a numeric result from an operation like:
>
>   select NUMERIC(8,4) '1.9999'
>   union
>   select INTEGER 4;

The typmod in postgres is not maintained very well. In the
wire-protocol the typmod is provided if known (the C interface calls
the function PQfmod) and if it's not there (which is very often,
postgres doesn't try very hard) there's no way to "encourge" postgres
to work it out for you.

As for no SQL level functions, you could probably write a function to
determine the scale/precision of a given *value*, but not for a whole
column.  But once you have to string representation of the value you
have that anyway...

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> He who writes carelessly confesses thereby at the very outset that he does
> not attach much importance to his own thoughts.
   -- Arthur Schopenhauer

Attachment

pgsql-general by date:

Previous
From: "David Johnston"
Date:
Subject: Re: stored procedure multiple call call question
Next
From: Jeff Janes
Date:
Subject: Re: Thousands of schemas and ANALYZE goes out of memory