Improve or throw proper error for COPY FROM in Citus foreign tables
- Dominant language
- C
- Stars
- 12.8k
- Forks
- 794
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 31
Description
COPY FROM doesn't work for Citus foreign tables. Currently it fails with this error coming from one of the worker nodes:
```SQL
-- steps to reproduce
SET citus.use_citus_managed_tables TO ON;
CREATE TABLE foreign_table_test (id integer NOT NULL, data text, a bigserial);
INSERT INTO foreign_table_test VALUES (1, 'text_test');
CREATE EXTENSION postgres_fdw;
CREATE SERVER foreign_server
FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (host 'localhost', port :'master_port', dbname 'regression');
CREATE USER MAPPING FOR CURRENT_USER
SERVER foreign_server
OPTIONS (user 'postgres');
CREATE FOREIGN TABLE foreign_table (
id integer NOT NULL,
data text,
a bigserial
)
SERVER foreign_server
OPTIONS (schema_name 'public', table_name 'foreign_table_test');
-- COPY FROM doesn't work for Citus foreign tables
COPY foreign_table FROM stdin;
1 1foo 2
\.
ERROR: cannot PREPARE a transaction that has operated on postgres_fdw foreign tables
```
It is a not a precise error. We should catch this error earlier more precisely in `EnsureCopyCanRunOnRelation`, with a message like `Citus cannot COPY into foreign tables`.
Also, we should make COPY not initiate a 2PC if it only touches a single shard. That way, we avoid this error in many cases.
Discussed with @onderkalaci @marcocitus https://github.com/citusdata/citus/pull/7160#discussion_r1314488889
Prioritized for 12.1 release.
Contributor guide
Assessment
This issue has not been assessed yet.