Re: BUG #12789: Views defined with VALUES lose their column names when dumped - Mailing list pgsql-bugs

From Andrew Gierth
Subject Re: BUG #12789: Views defined with VALUES lose their column names when dumped
Date
Msg-id 87ioexfb91.fsf@news-spur.riddles.org.uk
Whole thread Raw
In response to BUG #12789: Views defined with VALUES lose their column names when dumped  (programble@gmail.com)
Responses Re: BUG #12789: Views defined with VALUES lose their column names when dumped  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
>>>>> ">" == programble  <programble@gmail.com> writes:

 >> The following bug has been logged on the website:
 >> Bug reference:      12789
 >> Logged by:          Curtis McEnroe
 >> Email address:      programble@gmail.com
 >> PostgreSQL version: 9.4.1
 >> Operating system:   Mac OS X 10.10.1
 >> Description:

 >> A view created with explicit column names and defined as a VALUES statement
 >> will lose its column names when dumped. When the dump is restored, the
 >> view's columns are named "column1", "column2", etc.

 >> I wrote a short repro script here:
 >> https://gist.github.com/programble/a416df496bfb41259c86

For future reference and as a simpler testcase than the one in the
script:

# create view v1(a) as values (1);
CREATE VIEW

# select pg_get_viewdef('v1'::regclass);
 pg_get_viewdef
----------------
  VALUES (1);

Notice that the column name "a" is lost. Since pg_dump and so on rely on
pg_get_viewdef, dump and restore changes the column name back to
"column1".

The culprit is obviously in ruleutils.c:
get_simple_values_rte/get_values_def, which mistakenly thinks it only
has to deal with the result of transformValuesClause(), not considering
that the result of transformValuesClause might have been further
mogrified by DefineView. Treating this case as not being "simple" might
be one approach... not sure of the best way to detect that.

--
Andrew (irc:RhodiumToad)

pgsql-bugs by date:

Previous
From: programble@gmail.com
Date:
Subject: BUG #12789: Views defined with VALUES lose their column names when dumped
Next
From: lr@pcorp.us
Date:
Subject: BUG #12792: I can do a SELECT with no fields