Re: Precision of calculated numeric fields

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Travis Bauer <trbauer(at)indiana(dot)edu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Precision of calculated numeric fields
Date: 2000-06-06 16:10:50
Message-ID: 24397.960307850@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Travis Bauer <trbauer(at)indiana(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ron Peterson 2000-06-06 16:31:28 TRIGGER Syntax
Previous Message Robert B. Easter 2000-06-06 15:04:40 Re: How to backup db with large objects?