postgresql/src/include/commands
Tom Lane afc7328457 Prevent CREATE TABLE LIKE/INHERITS from (mis) copying whole-row Vars.
If a CHECK constraint or index definition contained a whole-row Var (that
is, "table.*"), an attempt to copy that definition via CREATE TABLE LIKE or
table inheritance produced incorrect results: the copied Var still claimed
to have the rowtype of the source table, rather than the created table.

For the LIKE case, it seems reasonable to just throw error for this
situation, since the point of LIKE is that the new table is not permanently
coupled to the old, so there's no reason to assume its rowtype will stay
compatible.  In the inheritance case, we should ideally allow such
constraints, but doing so will require nontrivial refactoring of CREATE
TABLE processing (because we'd need to know the OID of the new table's
rowtype before we adjust inherited CHECK constraints).  In view of the lack
of previous complaints, that doesn't seem worth the risk in a back-patched
bug fix, so just make it throw error for the inheritance case as well.

Along the way, replace change_varattnos_of_a_node() with a more robust
function map_variable_attnos(), which is capable of being extended to
handle insertion of ConvertRowtypeExpr whenever we get around to fixing
the inheritance case nicely, and in the meantime it returns a failure
indication to the caller so that a helpful message with some context can be
thrown.  Also, this code will do the right thing with subselects (if we
ever allow them in CHECK or indexes), and it range-checks varattnos before
using them to index into the map array.

Per report from Sergey Konoplev.  Back-patch to all supported branches.
2012-06-30 16:44:09 -04:00
..
alter.h Update copyright for the year 2010. 2010-01-02 16:58:17 +00:00
async.h Replace the pg_listener-based LISTEN/NOTIFY mechanism with an in-memory queue. 2010-02-16 22:34:57 +00:00
cluster.h Make ALTER TABLE revalidate uniqueness and exclusion constraints. 2011-01-20 22:48:29 -05:00
comment.h Update copyright for the year 2010. 2010-01-02 16:58:17 +00:00
conversioncmds.h Update copyright for the year 2010. 2010-01-02 16:58:17 +00:00
copy.h Update copyright for the year 2010. 2010-01-02 16:58:17 +00:00
dbcommands.h Update copyright for the year 2010. 2010-01-02 16:58:17 +00:00
defrem.h REASSIGN OWNED: Support foreign data wrappers and servers 2012-02-22 17:32:23 -03:00
discard.h Update copyright for the year 2010. 2010-01-02 16:58:17 +00:00
explain.h pgindent run for 9.0 2010-02-26 02:01:40 +00:00
lockcmds.h Update copyright for the year 2010. 2010-01-02 16:58:17 +00:00
portalcmds.h Update copyright for the year 2010. 2010-01-02 16:58:17 +00:00
prepare.h Update copyright for the year 2010. 2010-01-02 16:58:17 +00:00
proclang.h 8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list 2009-06-11 14:49:15 +00:00
schemacmds.h Update copyright for the year 2010. 2010-01-02 16:58:17 +00:00
sequence.h Remove all the special-case code for INT64_IS_BUSTED, per decision that 2010-01-07 04:53:35 +00:00
tablecmds.h Prevent CREATE TABLE LIKE/INHERITS from (mis) copying whole-row Vars. 2012-06-30 16:44:09 -04:00
tablespace.h Further fixes for per-tablespace options patch. 2010-01-07 03:53:08 +00:00
trigger.h Fix dangling-pointer problem in before-row update trigger processing. 2011-02-21 21:18:13 -05:00
typecmds.h Update copyright for the year 2010. 2010-01-02 16:58:17 +00:00
user.h Add a hook to CREATE/ALTER ROLE to allow an external module to check the 2009-11-18 21:57:56 +00:00
vacuum.h Fix VACUUM so that it always updates pg_class.reltuples/relpages. 2011-05-30 17:07:07 -04:00
variable.h Update copyright for the year 2010. 2010-01-02 16:58:17 +00:00
view.h Update copyright for the year 2010. 2010-01-02 16:58:17 +00:00