Skip to content

Commit

Permalink
file_fdw: Fix for generated columns
Browse files Browse the repository at this point in the history
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: Erik Rijkers <[email protected]>
  • Loading branch information
petere committed Apr 4, 2019
1 parent 6f0e190 commit 33215d1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions contrib/file_fdw/file_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,10 @@ check_selective_binary_conversion(RelOptInfo *baserel,
/* Skip dropped attributes (probably shouldn't see any here). */
if (attr->attisdropped)
continue;
/* Skip generated columns (COPY won't accept them in the column
* list) */
if (attr->attgenerated)
continue;
*columns = lappend(*columns, makeString(pstrdup(attname)));
}
}
Expand Down
6 changes: 6 additions & 0 deletions contrib/file_fdw/input/file_fdw.source
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ SELECT tableoid::regclass, * FROM p1;
SELECT tableoid::regclass, * FROM p2;
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
SET ROLE regress_file_fdw_superuser;
SELECT * FROM agg_text ORDER BY a;
Expand Down
11 changes: 11 additions & 0 deletions contrib/file_fdw/output/file_fdw.source
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,17 @@ SELECT tableoid::regclass, * FROM p2;
(3 rows)

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
SET ROLE regress_file_fdw_superuser;
SELECT * FROM agg_text ORDER BY a;
Expand Down

0 comments on commit 33215d1

Please sign in to comment.