agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Disallow system columns in COPY FROM WHERE conditions.
Date: Mon, 06 Apr 2026 18:05:22 +0000
Message-ID: <E1w9oK9-003Gl9-2N@gemulon.postgresql.org> (raw)

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(-)



Message-ID: <E1w9oK9-003Gl9-2N@gemulon.postgresql.org>
Permalink:  ../E1w9oK9-003Gl9-2N@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1w9oK9-003Gl9-2N@gemulon.postgresql.org

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Disallow system columns in COPY FROM WHERE conditions.
  In-Reply-To: <E1w9oK9-003Gl9-2N@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox