pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nathan Bossart <nathan@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix COPY FROM ... WHERE for negated operators.
Date: Tue, 06 Oct 2026 14:05:53 +0000
Message-ID: <E1xE5nl-00000000Yod-0aJX@gemulon.postgresql.org> (raw)

Fix COPY FROM ... WHERE for negated operators.

COPY FROM runs its WHERE clause through eval_const_expressions(),
which among other things replaces NOT above an operator with the
operator's negator, if it has one (e.g., NOT (a > 0) becomes
a <= 0).  The node it builds for the negator has no opfuncid, and
since COPY FROM never calls fix_opfuncids() on the clause, nothing
fills it in before the executor needs it.  So

        COPY tab FROM stdin WHERE NOT (a > 0)

fails with "cache lookup failed for function 0".

To fix, call fix_opfuncids() on the clause, as the relcache does
for index predicates.

Oversight in commit 31f3817402.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/asPZRTci4oBvxR9A%40nathan
Backpatch-through: 14

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a14041d437ff9e74d3596aea31bd202662e28800

Modified Files
--------------
src/backend/commands/copy.c         | 2 ++
src/test/regress/expected/copy2.out | 7 ++++++-
src/test/regress/sql/copy2.sql      | 6 ++++++
3 files changed, 14 insertions(+), 1 deletion(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1xE5nl-00000000Yod-0aJX@gemulon.postgresql.org>
Permalink:  ../E1xE5nl-00000000Yod-0aJX@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xE5nl-00000000Yod-0aJX@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: nathan@postgresql.org
  Subject: Re: pgsql: Fix COPY FROM ... WHERE for negated operators.
  In-Reply-To: <E1xE5nl-00000000Yod-0aJX@gemulon.postgresql.org>
  References: <E1xE5nl-00000000Yod-0aJX@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 DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox