Re: Precision of calculated numeric fields - Mailing list pgsql-general

From Tom Lane
Subject Re: Precision of calculated numeric fields
Date
Msg-id 24397.960307850@sss.pgh.pa.us
Whole thread Raw
In response to Precision of calculated numeric fields  (Travis Bauer <trbauer@indiana.edu>)
Responses Re: Precision of calculated numeric fields  (Travis Bauer <trbauer@indiana.edu>)
List pgsql-general
Travis Bauer <trbauer@indiana.edu> writes:
> Consider the following:
> trbauer=# create table t1 (x numberic(3,2));
> trbauer=# \d t1
> Attribute |   Type       | Modifier
> ------------------------------------
> X         | numeric(3,2) |

> trbauer=# create view v1 as select x*2 from t1;
> trbauer=# \d v1
> Attribute |     Type             | Modifier
> -------------------------------------------
> ?column?  | numeric(65535,65531) |

> How do I get the precision on the calculated numeric field to be something
> sane, like 3,2?

You don't --- there isn't any way to specify the types of view columns.
The view is being created with typmod -1 for the numeric column, which
is correct behavior IMHO.

The bug here is in psql: it should be showing the column type as plain
"numeric", no decoration.

> This is important for three reasons: 1.MSAccess chokes on views
> containing these fields (citing the precision size).  2. The jdbc driver
> takes _forever_ to retrieve these fields into big decimal.

Sounds like the jdbc driver also gets confused when it sees typmod -1
for a numeric field.

As a short-term workaround you could manually set pg_attribute's
atttypmod column for the view's field.  Use the same value you
find in atttypmod for the underlying table's field.

            regards, tom lane

pgsql-general by date:

Previous
From: "Robert B. Easter"
Date:
Subject: Re: How to backup db with large objects?
Next
From: Ron Peterson
Date:
Subject: TRIGGER Syntax