postgresql/src/backend
Tom Lane b978ab5f65 Partial fix for dropped columns in functions returning composite.
When a view has a function-returning-composite in FROM, and there are
some dropped columns in the underlying composite type, ruleutils.c
printed junk in the column alias list for the reconstructed FROM entry.
Before 9.3, this was prevented by doing get_rte_attribute_is_dropped
tests while printing the column alias list; but that solution is not
currently available to us for reasons I'll explain below.  Instead,
check for empty-string entries in the alias list, which can only exist
if that column position had been dropped at the time the view was made.
(The parser fills in empty strings to preserve the invariant that the
aliases correspond to physical column positions.)

While this is sufficient to handle the case of columns dropped before
the view was made, we have still got issues with columns dropped after
the view was made.  In particular, the view could contain Vars that
explicitly reference such columns!  The dependency machinery really
ought to refuse the column drop attempt in such cases, as it would do
when trying to drop a table column that's explicitly referenced in
views.  However, we currently neglect to store dependencies on columns
of composite types, and fixing that is likely to be too big to be
back-patchable (not to mention that existing views in existing databases
would not have the needed pg_depend entries anyway).  So I'll leave that
for a separate patch.

Pre-9.3, ruleutils would print such Vars normally (with their original
column names) even though it suppressed their entries in the RTE's
column alias list.  This is certainly bogus, since the printed view
definition would fail to reload, but at least it didn't crash.  However,
as of 9.3 the printed column alias list is tightly tied to the names
printed for Vars; so we can't treat columns as dropped for one purpose
and not dropped for the other.  This is why we can't just put back the
get_rte_attribute_is_dropped test: it results in an assertion failure
if the view in fact contains any Vars referencing the dropped column.
Once we've got dependencies preventing such cases, we'll probably want
to do it that way instead of relying on the empty-string test used here.

This fix turned up a very ancient bug in outfuncs/readfuncs, namely
that T_String nodes containing empty strings were not dumped/reloaded
correctly: the node was printed as "<>" which is read as a string
value of <>.  Since (per SQL) we disallow empty-string identifiers,
such nodes don't occur normally, which is why we'd not noticed.
(Such nodes aren't used for literal constants, just identifiers.)

Per report from Marc Schablewski.  Back-patch to 9.3 which is where
the rule printing behavior changed.  The dangling-variable case is
broken all the way back, but that's not what his complaint is about.
2014-07-19 14:29:05 -04:00
..
access Have multixact be truncated by checkpoint, not vacuum 2014-06-27 14:43:52 -04:00
bootstrap Revert "Fix bogus %name-prefix option syntax in all our Bison files." 2014-05-28 19:28:37 -04:00
catalog Fix REASSIGN OWNED for text search objects 2014-07-15 13:24:07 -04:00
commands Have multixact be truncated by checkpoint, not vacuum 2014-06-27 14:43:52 -04:00
executor Fix bug with whole-row references to append subplans. 2014-07-11 19:12:42 -04:00
foreign Arrange to cache FdwRoutine structs in foreign tables' relcache entries. 2013-03-06 23:48:09 -05:00
lib Remove tabs after spaces in C comments 2014-05-06 11:26:28 -04:00
libpq Remove tabs after spaces in C comments 2014-05-06 11:26:28 -04:00
main Remove tabs after spaces in C comments 2014-05-06 11:26:28 -04:00
nodes Partial fix for dropped columns in functions returning composite. 2014-07-19 14:29:05 -04:00
optimizer Don't assume a subquery's output is unique if there's a SRF in its tlist. 2014-07-08 14:03:19 -04:00
parser Revert "Fix bogus %name-prefix option syntax in all our Bison files." 2014-05-28 19:28:37 -04:00
po Translation updates 2014-03-16 21:57:58 -04:00
port Remove tabs after spaces in C comments 2014-05-06 11:26:28 -04:00
postmaster Fix unportable setvbuf() usage in initdb. 2014-05-15 15:57:57 -04:00
regex Fix two low-probability memory leaks in regular expression parsing. 2014-07-18 13:00:43 -04:00
replication Revert "Fix bogus %name-prefix option syntax in all our Bison files." 2014-05-28 19:28:37 -04:00
rewrite Add some errdetail to checkRuleResultList(). 2014-07-02 14:20:34 -04:00
snowball Fix ancient encoding error in hungarian.stop. 2014-06-10 22:48:39 -04:00
storage Add defenses against running with a wrong selection of LOBLKSIZE. 2014-06-05 11:31:09 -04:00
tcop Set the process latch when processing recovery conflict interrupts. 2014-06-03 14:13:31 +02:00
tsearch Remove tabs after spaces in C comments 2014-05-06 11:26:28 -04:00
utils Partial fix for dropped columns in functions returning composite. 2014-07-19 14:29:05 -04:00
.gitignore Add gitignore for mingw/cygwin build outputs 2011-06-09 18:11:47 +02:00
common.mk Call check_keywords.pl in maintainer-check 2012-02-27 13:53:12 +02:00
Makefile Move relpath() to libpgcommon 2013-02-21 22:46:17 -03:00
nls.mk Add libpgcommon to backend gettext source files 2013-10-21 06:20:05 -04:00