From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Andreas Kretschmer <akretschmer(at)spamfence(dot)net> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: data type change on a view |
Date: | 2007-12-12 21:56:15 |
Message-ID: | 26126.1197496575@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Andreas Kretschmer <akretschmer(at)spamfence(dot)net> writes:
>> cast it to varchar(8):
> As i said in a private mail to Scott (sorry): the suggested way don't
> work, at least with 8.1. Maybe this works better in more recent
> versions.
Yes, it works a lot better in 8.2:
http://archives.postgresql.org/pgsql-committers/2006-08/msg00222.php
If you really need the right output type in 8.1, you could force the
issue with an extra level of sub-select:
regression=# create table foo (f1 varchar(8));
CREATE TABLE
regression=# create view voo as select f1::varchar(8) from (select * from foo union select * from foo) ss;
CREATE VIEW
regression=# \d voo
View "public.voo"
Column | Type | Modifiers
--------+----------------------+-----------
f1 | character varying(8) |
View definition:
SELECT ss.f1::character varying(8) AS f1
FROM ( SELECT foo.f1
FROM foo
UNION
SELECT foo.f1
FROM foo) ss;
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Ivan Sergio Borgonovo | 2007-12-12 21:58:52 | Re: Extract last 4 characters from string? |
Previous Message | Rodrigo De León | 2007-12-12 21:40:02 | Re: Extract last 4 characters from string? |