pgsql: Disallow system columns in COPY FROM WHERE conditions. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Disallow system columns in COPY FROM WHERE conditions.
Date
Msg-id E1w9oK9-003Gl9-2N@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Disallow system columns in COPY FROM WHERE conditions.

These columns haven't been computed yet when the filtering happens
(since we've not written the candidate tuple into the table); so
any check on them is wrong or useless.  Worse, since aa606b931 such a
reference results in an access off the end of a TupleDesc, potentially
causing a phony "generated columns are not supported in COPY FROM
WHERE conditions" error; and since c98ad086a it throws an Assert
instead.

Actually we could allow tableoid, which has been set to the OID of the
table named as the COPY target.  However, plausible uses for tests of
tableoid would involve a partitioned target table, and the user would
wish it to read as the OID of the destination partition.  There has
been some discussion of changing things to make it work like that,
but pending that happening we should just disallow tableoid along
with other system columns.

It seems best though to install this prohibition only in HEAD.
In the back branches we'll just guard the unsafe TupleDesc access,
and people will keep getting whatever semantics they got before.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/6f435023-8ab6-47c2-ba07-035d0c4212f9@gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/21c69dc73f9d0af6a11f13ef61522577126a8674

Modified Files
--------------
src/backend/commands/copy.c         | 36 ++++++++++++++++++++++++++++--------
src/test/regress/expected/copy2.out |  3 +++
src/test/regress/sql/copy2.sql      |  2 ++
3 files changed, 33 insertions(+), 8 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Add missing .gitignore files.
Next
From: Álvaro Herrera
Date:
Subject: pgsql: Rename cluster.c to repack.c (and corresponding .h)