Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f8bd267

Browse files
committed
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.
1 parent c639d24 commit f8bd267

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

contrib/file_fdw/file_fdw.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,14 @@ file_fdw_validator(PG_FUNCTION_ARGS)
215215
*/
216216
ProcessCopyOptions(NULL, true, other_options);
217217

218+
/*
219+
* Filename option is required for file_fdw foreign tables.
220+
*/
221+
if (catalog == ForeignTableRelationId && filename == NULL)
222+
ereport(ERROR,
223+
(errcode(ERRCODE_FDW_DYNAMIC_PARAMETER_VALUE_NEEDED),
224+
errmsg("filename is required for file_fdw foreign tables")));
225+
218226
PG_RETURN_VOID();
219227
}
220228

@@ -286,10 +294,14 @@ fileGetOptions(Oid foreigntableid,
286294
}
287295
prev = lc;
288296
}
297+
298+
/*
299+
* The validator should have checked that a filename was included in the
300+
* options, but check again, just in case.
301+
*/
289302
if (*filename == NULL)
290-
ereport(ERROR,
291-
(errcode(ERRCODE_FDW_UNABLE_TO_CREATE_REPLY),
292-
errmsg("filename is required for file_fdw foreign tables")));
303+
elog(ERROR, "filename is required for file_fdw foreign tables");
304+
293305
*other_options = options;
294306
}
295307

contrib/file_fdw/input/file_fdw.source

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format 'csv', delimiter
5959
'); -- ERROR
6060
CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format 'csv', null '
6161
'); -- ERROR
62+
CREATE FOREIGN TABLE tbl () SERVER file_server; -- ERROR
6263

6364
CREATE FOREIGN TABLE agg_text (
6465
a int2,

contrib/file_fdw/output/file_fdw.source

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ ERROR: COPY delimiter cannot be newline or carriage return
7575
CREATE FOREIGN TABLE tbl () SERVER file_server OPTIONS (format 'csv', null '
7676
'); -- ERROR
7777
ERROR: COPY null representation cannot use newline or carriage return
78+
CREATE FOREIGN TABLE tbl () SERVER file_server; -- ERROR
79+
ERROR: filename is required for file_fdw foreign tables
7880
CREATE FOREIGN TABLE agg_text (
7981
a int2,
8082
b float4

0 commit comments

Comments
 (0)