Thread: Re: [GENERAL] replacing a view: bug or feature?

Re: [GENERAL] replacing a view: bug or feature?

From
Tom Lane
Date:
"Ed L." <pgsql@bluepolka.net> writes:
> CREATE TABLE foo ( "key" serial NOT NULL PRIMARY KEY, msg character(100));
> CREATE TABLE bar ( "key" serial NOT NULL PRIMARY KEY, msg character(100));
> CREATE VIEW baz AS SELECT * FROM foo UNION ALL SELECT * FROM bar;
> CREATE OR REPLACE VIEW baz AS SELECT * FROM foo;
> psql:foo.sql:6: ERROR:  cannot change data type of view column "msg"

The bottom-line issue here is that a UNION sets the typmod of its output
columns to -1, even when the inputs all share the same type OID and
typmod.  We changed that behavior some time ago for JOIN columns, and
probably ought to do the same for UNION columns.

I think this requires only a minor change in parser/analyze.c's
transformSetOperationStmt() ... any objections?
        regards, tom lane