Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6e6cc59

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 2e56fa8 commit 6e6cc59

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

contrib/file_fdw/file_fdw.c

+15-3
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ file_fdw_validator(PG_FUNCTION_ARGS)
216216
*/
217217
ProcessCopyOptions(NULL, true, other_options);
218218

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

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

contrib/file_fdw/input/file_fdw.source

+1
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

+2
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)