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 <[email protected]>
Discussion: https://postgr.es/m/asPZRTci4oBvxR9A%40nathan
Backpatch-through: 14

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/1adbe902ac86214782f295dac137997b523aa926

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

Reply via email to