Make the file_fdw validator check that a filename option has been provided.
authorTom Lane <[email protected]>
Tue, 5 Jul 2011 22:46:03 +0000 (18:46 -0400)
committerTom Lane <[email protected]>
Tue, 5 Jul 2011 22:46:03 +0000 (18:46 -0400)
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.

contrib/file_fdw/file_fdw.c
contrib/file_fdw/input/file_fdw.source
contrib/file_fdw/output/file_fdw.source

index f2d7f3a6a88f47b63aa20051d693f17e6b0dd05f..224e74ff32100ab1adf72f9075bd45049bad4a5e 100644 (file)
@@ -216,6 +216,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();
 }
 
@@ -287,10 +295,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;
 }
 
index 9ff7235a12468f270324419ca65522577a7ca17d..1405752819ced755a64c789013eed41bdff873e3 100644 (file)
@@ -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,
index 2ba36c936852d3d66643d23f98854e0da5ae3bca..6dd2653d0a7719ffcff0126e7935109b0d0d0a62 100644 (file)
@@ -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