Commit 6e6cc591 authored by Tom Lane's avatar Tom Lane

Make the file_fdw validator check that a filename option has been provided.

This was already a runtime failure condition, but it's better to check
at validation time if possible.  Lightly modified version of a patch
by Shigeru Hanada.
parent 2e56fa86
...@@ -216,6 +216,14 @@ file_fdw_validator(PG_FUNCTION_ARGS) ...@@ -216,6 +216,14 @@ file_fdw_validator(PG_FUNCTION_ARGS)
*/ */
ProcessCopyOptions(NULL, true, other_options); ProcessCopyOptions(NULL, true, other_options);
/*
* Filename option is required for file_fdw foreign tables.
*/
if (catalog == ForeignTableRelationId && filename == NULL)
ereport(ERROR,
(errcode(ERRCODE_FDW_DYNAMIC_PARAMETER_VALUE_NEEDED),
errmsg("filename is required for file_fdw foreign tables")));
PG_RETURN_VOID(); PG_RETURN_VOID();
} }
...@@ -287,10 +295,14 @@ fileGetOptions(Oid foreigntableid, ...@@ -287,10 +295,14 @@ fileGetOptions(Oid foreigntableid,
} }
prev = lc; prev = lc;
} }
/*
* The validator should have checked that a filename was included in the
* options, but check again, just in case.
*/
if (*filename == NULL) if (*filename == NULL)
ereport(ERROR, elog(ERROR, "filename is required for file_fdw foreign tables");
(errcode(ERRCODE_FDW_UNABLE_TO_CREATE_REPLY),
errmsg("filename is required for file_fdw foreign tables")));
*other_options = options; *other_options = options;
} }
......
...@@ -59,6 +59,7 @@ CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format 'csv', delimiter ...@@ -59,6 +59,7 @@ CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format 'csv', delimiter
'); -- ERROR '); -- ERROR
CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format 'csv', null ' CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format 'csv', null '
'); -- ERROR '); -- ERROR
CREATE FOREIGN TABLE tbl () SERVER file_server; -- ERROR
CREATE FOREIGN TABLE agg_text ( CREATE FOREIGN TABLE agg_text (
a int2, a int2,
......
...@@ -75,6 +75,8 @@ ERROR: COPY delimiter cannot be newline or carriage return ...@@ -75,6 +75,8 @@ ERROR: COPY delimiter cannot be newline or carriage return
CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format 'csv', null ' CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format 'csv', null '
'); -- ERROR '); -- ERROR
ERROR: COPY null representation cannot use newline or carriage return ERROR: COPY null representation cannot use newline or carriage return
CREATE FOREIGN TABLE tbl () SERVER file_server; -- ERROR
ERROR: filename is required for file_fdw foreign tables
CREATE FOREIGN TABLE agg_text ( CREATE FOREIGN TABLE agg_text (
a int2, a int2,
b float4 b float4
......
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