field definitions in view results?

Lists: pgsql-general
From: Klint Gore <kg(at)kgb(dot)une(dot)edu(dot)au>
To: pgsql-general(at)postgresql(dot)org
Subject: field definitions in view results?
Date: 2005-04-04 07:16:17
Message-ID: 4250E9C12A9.62B6KG@129.180.47.120
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

I'm having a problem that when I do a view with union between 2 tables
that have varchar(8) fields, that the (8) seems to be missing from the
result.

e.g. create table t1 (astr varchar(8));
create table t2 (astr varchar(8));
create view v1 as select * from t1 union select * from t2;
insert into t1 values ('STR');

in psql, "\d v1" gives "character varying" for the type.

Is there any way to get the (8) limit on the view result without doing
create view v1 as
select cast(v2.astr as varchar(8)) as astr
from (select * from t1 union select * from t2) v2

pg 7.4.7 on redhat linux 9.

klint.

+---------------------------------------+-----------------+
: Klint Gore : "Non rhyming :
: EMail : kg(at)kgb(dot)une(dot)edu(dot)au : slang - the :
: Snail : A.B.R.I. : possibilities :
: Mail University of New England : are useless" :
: Armidale NSW 2351 Australia : L.J.J. :
: Fax : +61 2 6772 5376 : :
+---------------------------------------+-----------------+


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Klint Gore <kg(at)kgb(dot)une(dot)edu(dot)au>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: field definitions in view results?
Date: 2005-04-04 15:14:02
Message-ID: 26108.1112627642@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Klint Gore <kg(at)kgb(dot)une(dot)edu(dot)au> writes:
> Is there any way to get the (8) limit on the view result without doing
> create view v1 as
> select cast(v2.astr as varchar(8)) as astr
> from (select * from t1 union select * from t2) v2

No. This is an open issue for 8.1, see
http://archives.postgresql.org/pgsql-general/2004-12/msg00508.php
http://archives.postgresql.org/pgsql-hackers/2004-12/msg00408.php

regards, tom lane