aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2019-04-04 09:24:48 +0200
committerPeter Eisentraut <peter@eisentraut.org>2019-04-04 09:24:48 +0200
commit33215d113d61980a4b2f2aec36cdcd21fa58c1c4 (patch)
tree78ba363e8c97db7573ed8a273a83bc34066bff81
parent6f0e190056fe441f7cf788ff19b62b13c94f68f3 (diff)
downloadpostgresql-33215d113d61980a4b2f2aec36cdcd21fa58c1c4.tar.gz
postgresql-33215d113d61980a4b2f2aec36cdcd21fa58c1c4.zip
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: Erik Rijkers <er@xs4all.nl>
-rw-r--r--contrib/file_fdw/file_fdw.c4
-rw-r--r--contrib/file_fdw/input/file_fdw.source6
-rw-r--r--contrib/file_fdw/output/file_fdw.source11
3 files changed, 21 insertions, 0 deletions
diff --git a/contrib/file_fdw/file_fdw.c b/contrib/file_fdw/file_fdw.c
index 391cd0d778d..85534a3a768 100644
--- a/contrib/file_fdw/file_fdw.c
+++ b/contrib/file_fdw/file_fdw.c
@@ -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)));
}
}
diff --git a/contrib/file_fdw/input/file_fdw.source b/contrib/file_fdw/input/file_fdw.source
index a5e79a4549a..45b728eeb3d 100644
--- a/contrib/file_fdw/input/file_fdw.source
+++ b/contrib/file_fdw/input/file_fdw.source
@@ -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;
diff --git a/contrib/file_fdw/output/file_fdw.source b/contrib/file_fdw/output/file_fdw.source
index 853c9f9b28b..52b4d5f1df7 100644
--- a/contrib/file_fdw/output/file_fdw.source
+++ b/contrib/file_fdw/output/file_fdw.source
@@ -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;