Defining Field Types with view

Defining Field Types with view

am 01.09.2004 22:27:14 von Traci.Sumpter

Cheesy one here....

I created a view similar to

Select field1, field2 from table
where field3 = 'Fred'
UNION
Select field1, field2 from table
where field3 = 'Wilma';

When the view contains just one sql statement the field definitions e.g.
charater varying (20) however when both are in the fields turn into
character varying (no size).

this is causing a problem when referring to the fields within Dephi/VB
because they think the varchar fields are memo.


I have got around it by creating another view which selects
field1::varchar(100) , field2 varchar(50) from firstview.


I have tried casting the fields within the first view but to no sucess.

Any way to get over this???

Cheers


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Re: Defining Field Types with view

am 02.09.2004 00:41:25 von tgl

"Traci Sumpter" writes:
> Cheesy one here....

Got a cheesy answer for you --- cast the result ...

regression=# create view voo as
regression-# select f1::varchar(20) from
regression-# (select f1 from foo union select f2 from foo) ss;
CREATE VIEW
regression=# \d voo
View "public.voo"
Column | Type | Modifiers
--------+-----------------------+-----------
f1 | character varying(20) |
View definition:
SELECT ss.f1::character varying(20) AS f1
FROM ( SELECT foo.f1
FROM foo
UNION
SELECT foo.f2
FROM foo) ss;

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match