COPY fails when the table has a row trigger
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
Research direction
Start by locating CockroachDB's COPY implementation and the row-level trigger handling it invokes; the issue does not name specific files or tests. Reproduce the supplied SQL case, then trace why COPY reports fewer inserted rows without an error when the trigger fires. Done means all three target rows and three log rows persist, matching the equivalent multi-row INSERT.
Written by the indexing model from the issue text.
Description
Describe the problem
Copying multiple rows into a table with a row-level trigger fails with an
internal error. The same inserts succeed when expressed as an ordinary
INSERT. The entire COPY is rolled back.
The reproduced error is:
ERROR: internal error: COPY didn't insert all buffered rows and yet no error was reported. Inserted 2 out of 3 rows.
To Reproduce
psql 'host=127.0.0.1 port=26257 user=root dbname=test sslmode=disable' <<'SQL'
DROP TABLE IF EXISTS copy_trigger_target;
DROP TABLE IF EXISTS copy_trigger_log;
DROP FUNCTION IF EXISTS copy_trigger_fn();
CREATE TABLE copy_trigger_target (a INT PRIMARY KEY, b INT);
CREATE TABLE copy_trigger_log (x TEXT);
CREATE FUNCTION copy_trigger_fn() RETURNS TRIGGER AS $$
BEGIN
INSERT INTO copy_trigger_log VALUES ('i');
RETURN NEW;
END
$$ LANGUAGE plpgsql;
CREATE TRIGGER copy_trigger
AFTER INSERT ON copy_trigger_target
FOR EACH ROW EXECUTE FUNCTION copy_trigger_fn();
SQL
printf '1,10\n2,20\n3,30\n' |
psql 'host=127.0.0.1 port=26257 user=root dbname=test sslmode=disable' \
-c 'COPY copy_trigger_target FROM STDIN WITH (FORMAT csv);'
# ERROR: internal error: COPY didn't insert all buffered rows and yet no error was
# reported. Inserted 2 out of 3 rows.
psql 'host=127.0.0.1 port=26257 user=root dbname=test sslmode=disable' \
-c 'SELECT count(*) FROM copy_trigger_target;' \
-c 'SELECT count(*) FROM copy_trigger_log;'
# count
# -------
# 0
# count
# -------
# 0
Expected behavior
The COPY should insert all three rows and fire the trigger once per inserted
row, matching the behavior of an equivalent multi-row INSERT. Both counts
shown above should be 3.
Environment:
- CockroachDB version:
v26.3.0-alpha.00000000-dev-13cb3eb27674b4a981e5c526d04c2387e81efd0b - Server OS: Linux amd64
- Client app:
psql16.15
Jira issue: CRDB-70500
- Dominant language
- Go
- Stars
- 32.6k
- Forks
- 4.2k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cockroachdb/cockroach
-
C-bug O-community X-blathers-untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
cockroachdb/cockroach#176245 · 1 comment ·
-
sql: pg_database.dattablespace is 0 but pg_tablespace.oid is 1663, so they no longer joinPossibly taken @1AbdullahButt claimed this 14 days ago. OpenC-bug O-community X-blathers-triaged X-move-internal
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
cockroachdb/cockroach#176228 · 1 comment ·
-
PG compat: overflow in integer power calculation triggers incompatible SQLSTATEMay be free again @darshpatel1052 claimed this 18 days ago, and no pull request is open. OpenC-bug O-community X-blathers-untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
cockroachdb/cockroach#176223 · 2 comments ·
-
util/log: bufferedSinkCloser.Close leaks a goroutine after timeoutPossibly taken @dajiaohuang claimed this 14 days ago. OpenC-bug O-community X-blathers-untriaged
Difficulty 1/5 Under an hour Newbie friendliness 84/100
cockroachdb/cockroach#176210 · 1 comment ·
-
C-bug O-community T-sql-queries X-blathers-triaged X-move-internal
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
cockroachdb/cockroach#176150 · 1 comment ·
All issues in cockroachdb/cockroach
Similar issues
-
area/import-export area/projects concern/ux
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
go-vikunja/vikunja#4455 · 1 comment ·
Maintainers usually reply within 2 days
-
Dependabot PRs no longer merge automaticallyPossibly taken @dwisiswant0 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
projectdiscovery/urlfinder#160 ·
Maintainers usually reply within 1 day
-
database
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
chnm/legal-modernism#450 ·
Maintainers usually reply within 1 day
-
tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
bug ready-for-triage ready-to-code
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
RedHatInsights/insights-ingress-go#946 · 4 comments ·
Maintainers usually reply within 1 day