COPY FROM ... WHERE fails for negated operators

Started by Nathan Bossart17 days ago3 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

This thread has been committed, so CI has stopped here. Anything below is the last result it produced.

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t254072
psql -h localhost -U postgres

Built from patchset v1 (message #1), October 05, 2026 at 05:17 PM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t254072_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t254072_1 && git checkout t254072_1

Patchset v1 (message #1) is on t254072_1

Jump to latest
#1Nathan Bossart
nathandbossart@gmail.com

The following steps produce a "cache lookup failed for function" error:

CREATE TABLE t (a int);
COPY t FROM stdin WHERE NOT (a > 0);
1
0
\.

I think what's happening is that negate_clause() is calling get_negator()
with a 0 argument because DoCopy() neglects to call fix_opfuncids() (like
RelationGetIndexPredicate() does). The attached patch fixes this.

--
nathan

Attachments:

t254072_1
v1-0001-Fix-COPY-FROM-.-WHERE-for-negated-operators.patchtext/plain; charset=us-asciiDownload+14-2
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Nathan Bossart (#1)
Re: COPY FROM ... WHERE fails for negated operators

Nathan Bossart <nathandbossart@gmail.com> writes:

The following steps produce a "cache lookup failed for function" error:
CREATE TABLE t (a int);
COPY t FROM stdin WHERE NOT (a > 0);
1
0
\.
I think what's happening is that negate_clause() is calling get_negator()
with a 0 argument because DoCopy() neglects to call fix_opfuncids() (like
RelationGetIndexPredicate() does). The attached patch fixes this.

Ugh. We really ought to get rid of fix_opfuncids() in favor of
insisting that operator clauses be filled in fully from the start.
But that's not happening right now, so I concur with this fix
for the moment.

regards, tom lane

#3Nathan Bossart
nathandbossart@gmail.com
In reply to: Tom Lane (#2)
Re: COPY FROM ... WHERE fails for negated operators

On Mon, Oct 05, 2026 at 01:48:44PM -0400, Tom Lane wrote:

Ugh. We really ought to get rid of fix_opfuncids() in favor of
insisting that operator clauses be filled in fully from the start.
But that's not happening right now, so I concur with this fix
for the moment.

Committed, thanks.

--
nathan