diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-07-05 18:46:03 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-07-05 18:46:09 -0400 |
commit | f8bd267d35503109255c99eae96c86ba8ba1b56f (patch) | |
tree | a47d4b60304a8b094923a5cffb07739dc99de051 | |
parent | c639d240c00f8d2b6684c03597b30d179d4ab31c (diff) | |
download | postgresql-f8bd267d35503109255c99eae96c86ba8ba1b56f.tar.gz postgresql-f8bd267d35503109255c99eae96c86ba8ba1b56f.zip |
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.
-rw-r--r-- | contrib/file_fdw/file_fdw.c | 18 | ||||
-rw-r--r-- | contrib/file_fdw/input/file_fdw.source | 1 | ||||
-rw-r--r-- | contrib/file_fdw/output/file_fdw.source | 2 |
3 files changed, 18 insertions, 3 deletions
diff --git a/contrib/file_fdw/file_fdw.c b/contrib/file_fdw/file_fdw.c index 466c015107d..4eb87e651bc 100644 --- a/contrib/file_fdw/file_fdw.c +++ b/contrib/file_fdw/file_fdw.c @@ -215,6 +215,14 @@ file_fdw_validator(PG_FUNCTION_ARGS) */ 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(); } @@ -286,10 +294,14 @@ fileGetOptions(Oid foreigntableid, } prev = lc; } + + /* + * The validator should have checked that a filename was included in the + * options, but check again, just in case. + */ if (*filename == NULL) - ereport(ERROR, - (errcode(ERRCODE_FDW_UNABLE_TO_CREATE_REPLY), - errmsg("filename is required for file_fdw foreign tables"))); + elog(ERROR, "filename is required for file_fdw foreign tables"); + *other_options = options; } diff --git a/contrib/file_fdw/input/file_fdw.source b/contrib/file_fdw/input/file_fdw.source index 9ff7235a124..1405752819c 100644 --- a/contrib/file_fdw/input/file_fdw.source +++ b/contrib/file_fdw/input/file_fdw.source @@ -59,6 +59,7 @@ CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format 'csv', delimiter '); -- ERROR CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format 'csv', null ' '); -- ERROR +CREATE FOREIGN TABLE tbl () SERVER file_server; -- ERROR CREATE FOREIGN TABLE agg_text ( a int2, diff --git a/contrib/file_fdw/output/file_fdw.source b/contrib/file_fdw/output/file_fdw.source index 2ba36c93685..6dd2653d0a7 100644 --- a/contrib/file_fdw/output/file_fdw.source +++ b/contrib/file_fdw/output/file_fdw.source @@ -75,6 +75,8 @@ ERROR: COPY delimiter cannot be newline or carriage return CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format 'csv', null ' '); -- ERROR 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 ( a int2, b float4 |