Fix file_fdw to require filename in its validator.
authorShigeru Hanada <[email protected]>
Thu, 30 Jun 2011 06:37:54 +0000 (15:37 +0900)
committerShigeru Hanada <[email protected]>
Fri, 1 Jul 2011 00:35:20 +0000 (09:35 +0900)
Before this fix, requirement of filename had been checked in
fileGetOptions() which is called by PlanForeignScan().  Now file_fdw can
check it in creation/alteration time.

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

index 466c015107db28b46601b759ad4542d6589a597c..a883f7551a54ae54953dba2d285c9be1de2b60f3 100644 (file)
@@ -215,6 +215,16 @@ file_fdw_validator(PG_FUNCTION_ARGS)
     */
    ProcessCopyOptions(NULL, true, other_options);
 
+   /*
+    * filename is a required option.  Validity of other options including
+    * relative ones have been checked in ProcessCopyOptions().
+    * Note: We don't care its value even though it might be empty, because
+    * COPY comand doesn't.
+    */
+   if (catalog == ForeignTableRelationId && filename == NULL)
+       ereport(ERROR,
+               (errmsg("filename is required for file_fdw foreign tables")));
+
    PG_RETURN_VOID();
 }
 
index 9ff7235a12468f270324419ca65522577a7ca17d..8d6dfa3c4ab27a92dc8e237db26217f5deef8d9b 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 OPTIONS (format 'csv');                       -- ERROR
 
 CREATE FOREIGN TABLE agg_text (
    a   int2,
index 2ba36c936852d3d66643d23f98854e0da5ae3bca..6cc6746b0ccc1187d4099c2ef72aa077a13d6db0 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 OPTIONS (format 'csv');                       -- ERROR
+ERROR:  filename is required for file_fdw foreign tables
 CREATE FOREIGN TABLE agg_text (
    a   int2,
    b   float4