| From: | Nathan Bossart <nathan(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Fix COPY FROM ... WHERE for negated operators. |
| Date: | 2026-10-06 14:05:53 |
| Message-ID: | E1xE5nl-00000000Yok-10T0@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
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(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/asPZRTci4oBvxR9A%40nathan
Backpatch-through: 14
Branch
------
REL_17_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/6b428e47b050bddb9316a53402fb19ac452c05bd
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(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Robert Haas | 2026-10-06 14:49:45 | Re: pgsql: Teach expr_is_nonnullable() to handle more expression types |
| Previous Message | Daniel Gustafsson | 2026-10-06 11:52:32 | pgsql: Clear SSL_hosts when destroying TLS |