Re: data type change on a view - Mailing list pgsql-general

From Scott Marlowe
Subject Re: data type change on a view
Date
Msg-id dcc563d10712121028n7564bdcdn1d2361fc91317f2b@mail.gmail.com
Whole thread Raw
In response to data type change on a view  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
Responses Re: data type change on a view
List pgsql-general
On Dec 12, 2007 12:11 PM, A. Kretschmer
<andreas.kretschmer@schollglas.com> wrote:
> Hello @all,
>
> i have a question (rot really for myself, a member of ther german forum
> asks):
>
> i have two tables, contains a varchar(N)-column. Now i create a VIEW
> based on this tables. The resulting view contains now a varchar without
> length. How can i prevent this? How can i force that the column in the
> view contains the *exact* typ?

cast it to varchar(8):

test=# create table h1 (t varchar(8));
CREATE TABLE
test=*# create table h2 (t varchar(8));
CREATE TABLE
test=*# create view h as select t::varchar(8) from h1 union all select
t from h2;
CREATE VIEW
test=*# \d h
             View "public.h"
  Column |       Type        | Modifiers
 --------+-------------------+-----------
  t      | character varying(8) |

Note that I don't have to do that in 8.2.5, it's automagic...

pgsql-general by date:

Previous
From: "Joshua D. Drake"
Date:
Subject: Re: Slow PITR restore
Next
From: "Scott Marlowe"
Date:
Subject: Re: General Q's