Commit 33215d11 authored by Peter Eisentraut's avatar Peter Eisentraut

file_fdw: Fix for generated columns

Since file_fdw uses COPY internally, but COPY doesn't allow listing
generated columns in its column list, we need to make sure that we
don't add generated columns to the column lists internally generated
by file_fdw.
Reported-by: default avatarErik Rijkers <er@xs4all.nl>
parent 6f0e1900
...@@ -922,6 +922,10 @@ check_selective_binary_conversion(RelOptInfo *baserel, ...@@ -922,6 +922,10 @@ check_selective_binary_conversion(RelOptInfo *baserel,
/* Skip dropped attributes (probably shouldn't see any here). */ /* Skip dropped attributes (probably shouldn't see any here). */
if (attr->attisdropped) if (attr->attisdropped)
continue; continue;
/* Skip generated columns (COPY won't accept them in the column
* list) */
if (attr->attgenerated)
continue;
*columns = lappend(*columns, makeString(pstrdup(attname))); *columns = lappend(*columns, makeString(pstrdup(attname)));
} }
} }
......
...@@ -189,6 +189,12 @@ SELECT tableoid::regclass, * FROM p1; ...@@ -189,6 +189,12 @@ SELECT tableoid::regclass, * FROM p1;
SELECT tableoid::regclass, * FROM p2; SELECT tableoid::regclass, * FROM p2;
DROP TABLE pt; DROP TABLE pt;
-- generated column tests
CREATE FOREIGN TABLE gft1 (a int, b text, c text GENERATED ALWAYS AS ('foo') STORED) SERVER file_server
OPTIONS (format 'csv', filename '@abs_srcdir@/data/list1.csv', delimiter ',');
SELECT a, c FROM gft1;
DROP FOREIGN TABLE gft1;
-- privilege tests -- privilege tests
SET ROLE regress_file_fdw_superuser; SET ROLE regress_file_fdw_superuser;
SELECT * FROM agg_text ORDER BY a; SELECT * FROM agg_text ORDER BY a;
......
...@@ -375,6 +375,17 @@ SELECT tableoid::regclass, * FROM p2; ...@@ -375,6 +375,17 @@ SELECT tableoid::regclass, * FROM p2;
(3 rows) (3 rows)
DROP TABLE pt; DROP TABLE pt;
-- generated column tests
CREATE FOREIGN TABLE gft1 (a int, b text, c text GENERATED ALWAYS AS ('foo') STORED) SERVER file_server
OPTIONS (format 'csv', filename '@abs_srcdir@/data/list1.csv', delimiter ',');
SELECT a, c FROM gft1;
a | c
---+--------
1 | _null_
1 | _null_
(2 rows)
DROP FOREIGN TABLE gft1;
-- privilege tests -- privilege tests
SET ROLE regress_file_fdw_superuser; SET ROLE regress_file_fdw_superuser;
SELECT * FROM agg_text ORDER BY a; SELECT * FROM agg_text ORDER BY a;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment