Re: pg_typeof equivalent for numeric scale, numeric/timestamp precision?

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Craig Ringer <ringerc(at)ringerc(dot)id(dot)au>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: pg_typeof equivalent for numeric scale, numeric/timestamp precision?
Date: 2012-10-02 21:50:28
Message-ID: 20121002215027.GF11163@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)svana(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Royce Ausburn 2012-10-03 00:05:42 invalid page header in block...
Previous Message David Johnston 2012-10-02 21:37:40 Re: stored procedure multiple call call question