{"kind": "fdw", "major": "18", "item": {"slug": "file_fdw", "name": "file_fdw", "name_zh": "Server files", "category": "Server files", "summary": "Reads server-side files or program output through the foreign-data wrapper interface.", "aliases": [], "content_hash": "c584bcf961f646facb34f819b6db7b99a0e4024434cff56684c2c803ac8bb38f", "versions": {"10": {"facts": [{"label": "Interface family", "value": "Foreign-data wrapper"}, {"label": "Handler or routine", "value": "file_fdw_handler"}, {"label": "Recorded callbacks", "value": "10"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "fileIterateForeignScan"}, {"state": "No handler registered in this build", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "Not registered"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether the data has a header line, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=10", "label": "Foreign-data wrapper catalog"}, {"url": "/e/file_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=10", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 10.23 source archive", "label": "10.23", "major": "10", "channel": "historical", "revision": "94a4b2528372458e5662c18d406629266667c437198160a18cdfd2c4a4d6eee9", "source_url": "https://ftp.postgresql.org/pub/source/v10.23/postgresql-10.23.tar.bz2", "source_snapshot_utc": ""}, "sources": [{"url": "/docs/10/file-fdw.html", "path": "file-fdw.html", "label": "PostgreSQL 10 English manual", "sha256": "2c49f46e371f19bba82d29145505e94032593c7bb4dabf095ca55256ebd7808b"}, {"url": "https://ftp.postgresql.org/pub/source/v10.23/postgresql-10.23.tar.bz2", "line": 170, "path": "contrib/file_fdw/file_fdw.c", "label": "contrib/file_fdw/file_fdw.c:170", "sha256": "a24eff98f652c7f49aa53495a0be689db2dd8f24749fb4cf955a8d6aeb845c70", "archive_sha256": "94a4b2528372458e5662c18d406629266667c437198160a18cdfd2c4a4d6eee9"}], "sections": [{"title": "Interface and capability boundaries", "paragraphs": ["The matrix records callbacks actually registered in this source build. Registration identifies an implemented interface hook; options, query shape, privileges and provider rules determine whether an operation is allowed.", "The complete same-version manual below retains configuration, constraints and examples. No runtime capability test is claimed."]}, {"title": "File access boundary", "paragraphs": ["The file_fdw module provides the foreign-data wrapper file_fdw , which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by COPY FROM ; see COPY for details. Access to data files is currently read-only."]}, {"code": "{\n\tFdwRoutine *fdwroutine = makeNode(FdwRoutine);\n\n\tfdwroutine->GetForeignRelSize = fileGetForeignRelSize;\n\tfdwroutine->GetForeignPaths = fileGetForeignPaths;\n\tfdwroutine->GetForeignPlan = fileGetForeignPlan;\n\tfdwroutine->ExplainForeignScan = fileExplainForeignScan;\n\tfdwroutine->BeginForeignScan = fileBeginForeignScan;\n\tfdwroutine->IterateForeignScan = fileIterateForeignScan;\n\tfdwroutine->ReScanForeignScan = fileReScanForeignScan;\n\tfdwroutine->EndForeignScan = fileEndForeignScan;\n\tfdwroutine->AnalyzeForeignTable = fileAnalyzeForeignTable;\n\tfdwroutine->IsForeignScanParallelSafe = fileIsForeignScanParallelSafe;\n\n\tPG_RETURN_POINTER(fdwroutine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "description": ["Reads server-side files or program output through the foreign-data wrapper interface."], "manual_html": "<div class=\"sect1\" id=\"FILE-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.15.\u00a0file_fdw</h2>\n</div>\n</div>\n</div>\n\n<p>The <code class=\"filename\">file_fdw</code> module provides the foreign-data wrapper <code class=\"function\">file_fdw</code>, which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by <code class=\"command\">COPY FROM</code>; see <a class=\"xref\" href=\"/docs/10/sql-copy.html\" title=\"COPY\"><span class=\"refentrytitle\">COPY</span></a> for details. Access to data files is currently read-only.</p>\n<p>A foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">filename</code></span></dt>\n<dd>\n<p>Specifies the file to be read. Relative paths are relative to the data directory. Either <code class=\"literal\">filename</code> or <code class=\"literal\">program</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">program</code></span></dt>\n<dd>\n<p>Specifies the command to be executed. The standard output of this command will be read as though <code class=\"command\">COPY FROM PROGRAM</code> were used. Either <code class=\"literal\">program</code> or <code class=\"literal\">filename</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">format</code></span></dt>\n<dd>\n<p>Specifies the data format, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">FORMAT</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">header</code></span></dt>\n<dd>\n<p>Specifies whether the data has a header line, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">HEADER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">delimiter</code></span></dt>\n<dd>\n<p>Specifies the data delimiter character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">DELIMITER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">quote</code></span></dt>\n<dd>\n<p>Specifies the data quote character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">QUOTE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">escape</code></span></dt>\n<dd>\n<p>Specifies the data escape character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ESCAPE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">null</code></span></dt>\n<dd>\n<p>Specifies the data null string, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">encoding</code></span></dt>\n<dd>\n<p>Specifies the data encoding, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ENCODING</code> option.</p>\n</dd>\n</dl>\n</div>\n<p>Note that while <code class=\"command\">COPY</code> allows options such as <code class=\"literal\">HEADER</code> to be specified without a corresponding value, the foreign table option syntax requires a value to be present in all cases. To activate <code class=\"command\">COPY</code> options typically written without a value, you can pass the value TRUE, since all such options are Booleans.</p>\n<p>A column of a foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">force_not_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level <code class=\"literal\">null</code> option). This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NOT_NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">force_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as <code class=\"literal\">NULL</code> even if the value is quoted. Without this option, only unquoted values matching the null string are returned as <code class=\"literal\">NULL</code>. This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NULL</code> option.</p>\n</dd>\n</dl>\n</div>\n<p><code class=\"command\">COPY</code>'s <code class=\"literal\">OIDS</code> and <code class=\"literal\">FORCE_QUOTE</code> options are currently not supported by <code class=\"literal\">file_fdw</code>.</p>\n<p>These options can only be specified for a foreign table or its columns, not in the options of the <code class=\"literal\">file_fdw</code> foreign-data wrapper, nor in the options of a server or user mapping using the wrapper.</p>\n<p>Changing table-level options requires superuser privileges, for security reasons: only a superuser should be able to control which file is read or which program is run. In principle non-superusers could be allowed to change the other options, but that's not supported at present.</p>\n<p>When specifying the <code class=\"literal\">program</code> option, keep in mind that the option string is executed by the shell. If you need to pass any arguments to the command that come from an untrusted source, you must be careful to strip or escape any characters that might have special meaning to the shell. For security reasons, it is best to use a fixed command string, or at least avoid passing any user input in it.</p>\n<p>For a foreign table using <code class=\"literal\">file_fdw</code>, <code class=\"command\">EXPLAIN</code> shows the name of the file to be read or program to be run. For a file, unless <code class=\"literal\">COSTS OFF</code> is specified, the file size (in bytes) is shown as well.</p>\n<div class=\"example\" id=\"id-1.11.7.24.14\">\n<p class=\"title\"><strong>Example\u00a0F.1.\u00a0Create a Foreign Table for PostgreSQL CSV Logs</strong></p>\n<div class=\"example-contents\">\n<p>One of the obvious uses for <code class=\"literal\">file_fdw</code> is to make the PostgreSQL activity log available as a table for querying. To do this, first you must be <a class=\"link\" href=\"/docs/10/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-CSVLOG\" title=\"19.8.4.\u00a0Using CSV-Format Log Output\">logging to a CSV file,</a> which here we will call <code class=\"literal\">pglog.csv</code>. First, install <code class=\"literal\">file_fdw</code> as an extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION file_fdw;\n</pre>\n<p>Then create a foreign server:</p>\n<pre class=\"programlisting\">CREATE SERVER pglog FOREIGN DATA WRAPPER file_fdw;\n</pre>\n<p>Now you are ready to create the foreign data table. Using the <code class=\"command\">CREATE FOREIGN TABLE</code> command, you will need to define the columns for the table, the CSV file name, and its format:</p>\n<pre class=\"programlisting\">CREATE FOREIGN TABLE pglog (\n  log_time timestamp(3) with time zone,\n  user_name text,\n  database_name text,\n  process_id integer,\n  connection_from text,\n  session_id text,\n  session_line_num bigint,\n  command_tag text,\n  session_start_time timestamp with time zone,\n  virtual_transaction_id text,\n  transaction_id bigint,\n  error_severity text,\n  sql_state_code text,\n  message text,\n  detail text,\n  hint text,\n  internal_query text,\n  internal_query_pos integer,\n  context text,\n  query text,\n  query_pos integer,\n  location text,\n  application_name text\n) SERVER pglog\nOPTIONS ( filename '/home/josh/data/log/pglog.csv', format 'csv' );\n</pre>\n<p>That's it \u2014 now you can query your log directly. In production, of course, you would need to define some way to deal with log rotation.</p>\n</div>\n</div>\n<br class=\"example-break\"></div>", "manual_path": "/docs/10/file-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether the data has a header line, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "e3667962550d31793ff1cfb28056ac711b0cfd15ff9da272242f5b472d17c327", "runtime_verified": false}, "11": {"facts": [{"label": "Interface family", "value": "Foreign-data wrapper"}, {"label": "Handler or routine", "value": "file_fdw_handler"}, {"label": "Recorded callbacks", "value": "10"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "fileIterateForeignScan"}, {"state": "No handler registered in this build", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "Not registered"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether the data has a header line, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=11", "label": "Foreign-data wrapper catalog"}, {"url": "/e/file_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=11", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 11.22 source archive", "label": "11.22", "major": "11", "channel": "historical", "revision": "2cb7c97d7a0d7278851bbc9c61f467b69c094c72b81740b751108e7892ebe1f0", "source_url": "https://ftp.postgresql.org/pub/source/v11.22/postgresql-11.22.tar.bz2", "source_snapshot_utc": ""}, "sources": [{"url": "/docs/11/file-fdw.html", "path": "file-fdw.html", "label": "PostgreSQL 11 English manual", "sha256": "a093c1a343e390c649afdec716275796f917757c684cffc97832e71cadf4f97b"}, {"url": "https://ftp.postgresql.org/pub/source/v11.22/postgresql-11.22.tar.bz2", "line": 171, "path": "contrib/file_fdw/file_fdw.c", "label": "contrib/file_fdw/file_fdw.c:171", "sha256": "c2612324f035b7416674c9c8762baea085033b8257c3a1963d7cf34f4f15ecf8", "archive_sha256": "2cb7c97d7a0d7278851bbc9c61f467b69c094c72b81740b751108e7892ebe1f0"}], "sections": [{"title": "Interface and capability boundaries", "paragraphs": ["The matrix records callbacks actually registered in this source build. Registration identifies an implemented interface hook; options, query shape, privileges and provider rules determine whether an operation is allowed.", "The complete same-version manual below retains configuration, constraints and examples. No runtime capability test is claimed."]}, {"title": "File access boundary", "paragraphs": ["The file_fdw module provides the foreign-data wrapper file_fdw , which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by COPY FROM ; see COPY for details. Access to data files is currently read-only."]}, {"code": "{\n\tFdwRoutine *fdwroutine = makeNode(FdwRoutine);\n\n\tfdwroutine->GetForeignRelSize = fileGetForeignRelSize;\n\tfdwroutine->GetForeignPaths = fileGetForeignPaths;\n\tfdwroutine->GetForeignPlan = fileGetForeignPlan;\n\tfdwroutine->ExplainForeignScan = fileExplainForeignScan;\n\tfdwroutine->BeginForeignScan = fileBeginForeignScan;\n\tfdwroutine->IterateForeignScan = fileIterateForeignScan;\n\tfdwroutine->ReScanForeignScan = fileReScanForeignScan;\n\tfdwroutine->EndForeignScan = fileEndForeignScan;\n\tfdwroutine->AnalyzeForeignTable = fileAnalyzeForeignTable;\n\tfdwroutine->IsForeignScanParallelSafe = fileIsForeignScanParallelSafe;\n\n\tPG_RETURN_POINTER(fdwroutine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "description": ["Reads server-side files or program output through the foreign-data wrapper interface."], "manual_html": "<div class=\"sect1\" id=\"FILE-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.14.\u00a0file_fdw</h2>\n</div>\n</div>\n</div>\n<p>The <code class=\"filename\">file_fdw</code> module provides the foreign-data wrapper <code class=\"function\">file_fdw</code>, which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by <code class=\"command\">COPY FROM</code>; see <a class=\"xref\" href=\"/docs/11/sql-copy.html\" title=\"COPY\"><span class=\"refentrytitle\">COPY</span></a> for details. Access to data files is currently read-only.</p>\n<p>A foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">filename</code></span></dt>\n<dd>\n<p>Specifies the file to be read. Relative paths are relative to the data directory. Either <code class=\"literal\">filename</code> or <code class=\"literal\">program</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">program</code></span></dt>\n<dd>\n<p>Specifies the command to be executed. The standard output of this command will be read as though <code class=\"command\">COPY FROM PROGRAM</code> were used. Either <code class=\"literal\">program</code> or <code class=\"literal\">filename</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">format</code></span></dt>\n<dd>\n<p>Specifies the data format, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">FORMAT</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">header</code></span></dt>\n<dd>\n<p>Specifies whether the data has a header line, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">HEADER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">delimiter</code></span></dt>\n<dd>\n<p>Specifies the data delimiter character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">DELIMITER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">quote</code></span></dt>\n<dd>\n<p>Specifies the data quote character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">QUOTE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">escape</code></span></dt>\n<dd>\n<p>Specifies the data escape character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ESCAPE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">null</code></span></dt>\n<dd>\n<p>Specifies the data null string, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">encoding</code></span></dt>\n<dd>\n<p>Specifies the data encoding, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ENCODING</code> option.</p>\n</dd>\n</dl>\n</div>\n<p>Note that while <code class=\"command\">COPY</code> allows options such as <code class=\"literal\">HEADER</code> to be specified without a corresponding value, the foreign table option syntax requires a value to be present in all cases. To activate <code class=\"command\">COPY</code> options typically written without a value, you can pass the value TRUE, since all such options are Booleans.</p>\n<p>A column of a foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">force_not_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level <code class=\"literal\">null</code> option). This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NOT_NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">force_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as <code class=\"literal\">NULL</code> even if the value is quoted. Without this option, only unquoted values matching the null string are returned as <code class=\"literal\">NULL</code>. This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NULL</code> option.</p>\n</dd>\n</dl>\n</div>\n<p><code class=\"command\">COPY</code>'s <code class=\"literal\">OIDS</code> and <code class=\"literal\">FORCE_QUOTE</code> options are currently not supported by <code class=\"literal\">file_fdw</code>.</p>\n<p>These options can only be specified for a foreign table or its columns, not in the options of the <code class=\"literal\">file_fdw</code> foreign-data wrapper, nor in the options of a server or user mapping using the wrapper.</p>\n<p>Changing table-level options requires being a superuser or having the privileges of the default role <code class=\"literal\">pg_read_server_files</code> (to use a filename) or the default role <code class=\"literal\">pg_execute_server_program</code> (to use a program), for security reasons: only certain users should be able to control which file is read or which program is run. In principle regular users could be allowed to change the other options, but that's not supported at present.</p>\n<p>When specifying the <code class=\"literal\">program</code> option, keep in mind that the option string is executed by the shell. If you need to pass any arguments to the command that come from an untrusted source, you must be careful to strip or escape any characters that might have special meaning to the shell. For security reasons, it is best to use a fixed command string, or at least avoid passing any user input in it.</p>\n<p>For a foreign table using <code class=\"literal\">file_fdw</code>, <code class=\"command\">EXPLAIN</code> shows the name of the file to be read or program to be run. For a file, unless <code class=\"literal\">COSTS OFF</code> is specified, the file size (in bytes) is shown as well.</p>\n<div class=\"example\" id=\"id-1.11.7.23.14\">\n<p class=\"title\"><strong>Example\u00a0F.1.\u00a0Create a Foreign Table for PostgreSQL CSV Logs</strong></p>\n<div class=\"example-contents\">\n<p>One of the obvious uses for <code class=\"literal\">file_fdw</code> is to make the PostgreSQL activity log available as a table for querying. To do this, first you must be <a class=\"link\" href=\"/docs/11/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-CSVLOG\" title=\"19.8.4.\u00a0Using CSV-Format Log Output\">logging to a CSV file,</a> which here we will call <code class=\"literal\">pglog.csv</code>. First, install <code class=\"literal\">file_fdw</code> as an extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION file_fdw;\n</pre>\n<p>Then create a foreign server:</p>\n<pre class=\"programlisting\">CREATE SERVER pglog FOREIGN DATA WRAPPER file_fdw;\n</pre>\n<p>Now you are ready to create the foreign data table. Using the <code class=\"command\">CREATE FOREIGN TABLE</code> command, you will need to define the columns for the table, the CSV file name, and its format:</p>\n<pre class=\"programlisting\">CREATE FOREIGN TABLE pglog (\n  log_time timestamp(3) with time zone,\n  user_name text,\n  database_name text,\n  process_id integer,\n  connection_from text,\n  session_id text,\n  session_line_num bigint,\n  command_tag text,\n  session_start_time timestamp with time zone,\n  virtual_transaction_id text,\n  transaction_id bigint,\n  error_severity text,\n  sql_state_code text,\n  message text,\n  detail text,\n  hint text,\n  internal_query text,\n  internal_query_pos integer,\n  context text,\n  query text,\n  query_pos integer,\n  location text,\n  application_name text\n) SERVER pglog\nOPTIONS ( filename '/home/josh/data/log/pglog.csv', format 'csv' );\n</pre>\n<p>That's it \u2014 now you can query your log directly. In production, of course, you would need to define some way to deal with log rotation.</p>\n</div>\n</div><br class=\"example-break\">\n</div>", "manual_path": "/docs/11/file-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether the data has a header line, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "e3667962550d31793ff1cfb28056ac711b0cfd15ff9da272242f5b472d17c327", "runtime_verified": false}, "12": {"facts": [{"label": "Interface family", "value": "Foreign-data wrapper"}, {"label": "Handler or routine", "value": "file_fdw_handler"}, {"label": "Recorded callbacks", "value": "10"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "fileIterateForeignScan"}, {"state": "No handler registered in this build", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "Not registered"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether the data has a header line, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=12", "label": "Foreign-data wrapper catalog"}, {"url": "/e/file_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=12", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 12.22 source archive", "label": "12.22", "major": "12", "channel": "historical", "revision": "8df3c0474782589d3c6f374b5133b1bd14d168086edbc13c6e72e67dd4527a3b", "source_url": "https://ftp.postgresql.org/pub/source/v12.22/postgresql-12.22.tar.bz2", "source_snapshot_utc": ""}, "sources": [{"url": "/docs/12/file-fdw.html", "path": "file-fdw.html", "label": "PostgreSQL 12 English manual", "sha256": "56a0b61b2cbf0d1aca9240a2fdc451d1f52e808bc77228a908c62c2ed6bfd6f8"}, {"url": "https://ftp.postgresql.org/pub/source/v12.22/postgresql-12.22.tar.bz2", "line": 171, "path": "contrib/file_fdw/file_fdw.c", "label": "contrib/file_fdw/file_fdw.c:171", "sha256": "7653549d5399d68e26b5a622e91b809be4018ce732dee898f00aa07eee5a2271", "archive_sha256": "8df3c0474782589d3c6f374b5133b1bd14d168086edbc13c6e72e67dd4527a3b"}], "sections": [{"title": "Interface and capability boundaries", "paragraphs": ["The matrix records callbacks actually registered in this source build. Registration identifies an implemented interface hook; options, query shape, privileges and provider rules determine whether an operation is allowed.", "The complete same-version manual below retains configuration, constraints and examples. No runtime capability test is claimed."]}, {"title": "File access boundary", "paragraphs": ["The file_fdw module provides the foreign-data wrapper file_fdw , which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by COPY FROM ; see COPY for details. Access to data files is currently read-only."]}, {"code": "{\n\tFdwRoutine *fdwroutine = makeNode(FdwRoutine);\n\n\tfdwroutine->GetForeignRelSize = fileGetForeignRelSize;\n\tfdwroutine->GetForeignPaths = fileGetForeignPaths;\n\tfdwroutine->GetForeignPlan = fileGetForeignPlan;\n\tfdwroutine->ExplainForeignScan = fileExplainForeignScan;\n\tfdwroutine->BeginForeignScan = fileBeginForeignScan;\n\tfdwroutine->IterateForeignScan = fileIterateForeignScan;\n\tfdwroutine->ReScanForeignScan = fileReScanForeignScan;\n\tfdwroutine->EndForeignScan = fileEndForeignScan;\n\tfdwroutine->AnalyzeForeignTable = fileAnalyzeForeignTable;\n\tfdwroutine->IsForeignScanParallelSafe = fileIsForeignScanParallelSafe;\n\n\tPG_RETURN_POINTER(fdwroutine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "description": ["Reads server-side files or program output through the foreign-data wrapper interface."], "manual_html": "<div class=\"sect1\" id=\"FILE-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.14.\u00a0file_fdw</h2>\n</div>\n</div>\n</div>\n<p>The <code class=\"filename\">file_fdw</code> module provides the foreign-data wrapper <code class=\"function\">file_fdw</code>, which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by <code class=\"command\">COPY FROM</code>; see <a class=\"xref\" href=\"/docs/12/sql-copy.html\" title=\"COPY\"><span class=\"refentrytitle\">COPY</span></a> for details. Access to data files is currently read-only.</p>\n<p>A foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">filename</code></span></dt>\n<dd>\n<p>Specifies the file to be read. Relative paths are relative to the data directory. Either <code class=\"literal\">filename</code> or <code class=\"literal\">program</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">program</code></span></dt>\n<dd>\n<p>Specifies the command to be executed. The standard output of this command will be read as though <code class=\"command\">COPY FROM PROGRAM</code> were used. Either <code class=\"literal\">program</code> or <code class=\"literal\">filename</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">format</code></span></dt>\n<dd>\n<p>Specifies the data format, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">FORMAT</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">header</code></span></dt>\n<dd>\n<p>Specifies whether the data has a header line, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">HEADER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">delimiter</code></span></dt>\n<dd>\n<p>Specifies the data delimiter character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">DELIMITER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">quote</code></span></dt>\n<dd>\n<p>Specifies the data quote character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">QUOTE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">escape</code></span></dt>\n<dd>\n<p>Specifies the data escape character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ESCAPE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">null</code></span></dt>\n<dd>\n<p>Specifies the data null string, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">encoding</code></span></dt>\n<dd>\n<p>Specifies the data encoding, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ENCODING</code> option.</p>\n</dd>\n</dl>\n</div>\n<p>Note that while <code class=\"command\">COPY</code> allows options such as <code class=\"literal\">HEADER</code> to be specified without a corresponding value, the foreign table option syntax requires a value to be present in all cases. To activate <code class=\"command\">COPY</code> options typically written without a value, you can pass the value TRUE, since all such options are Booleans.</p>\n<p>A column of a foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">force_not_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level <code class=\"literal\">null</code> option). This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NOT_NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">force_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as <code class=\"literal\">NULL</code> even if the value is quoted. Without this option, only unquoted values matching the null string are returned as <code class=\"literal\">NULL</code>. This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NULL</code> option.</p>\n</dd>\n</dl>\n</div>\n<p><code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_QUOTE</code> option is currently not supported by <code class=\"literal\">file_fdw</code>.</p>\n<p>These options can only be specified for a foreign table or its columns, not in the options of the <code class=\"literal\">file_fdw</code> foreign-data wrapper, nor in the options of a server or user mapping using the wrapper.</p>\n<p>Changing table-level options requires being a superuser or having the privileges of the default role <code class=\"literal\">pg_read_server_files</code> (to use a filename) or the default role <code class=\"literal\">pg_execute_server_program</code> (to use a program), for security reasons: only certain users should be able to control which file is read or which program is run. In principle regular users could be allowed to change the other options, but that's not supported at present.</p>\n<p>When specifying the <code class=\"literal\">program</code> option, keep in mind that the option string is executed by the shell. If you need to pass any arguments to the command that come from an untrusted source, you must be careful to strip or escape any characters that might have special meaning to the shell. For security reasons, it is best to use a fixed command string, or at least avoid passing any user input in it.</p>\n<p>For a foreign table using <code class=\"literal\">file_fdw</code>, <code class=\"command\">EXPLAIN</code> shows the name of the file to be read or program to be run. For a file, unless <code class=\"literal\">COSTS OFF</code> is specified, the file size (in bytes) is shown as well.</p>\n<div class=\"example\" id=\"id-1.11.7.23.14\">\n<p class=\"title\"><strong>Example\u00a0F.1.\u00a0Create a Foreign Table for PostgreSQL CSV Logs</strong></p>\n<div class=\"example-contents\">\n<p>One of the obvious uses for <code class=\"literal\">file_fdw</code> is to make the PostgreSQL activity log available as a table for querying. To do this, first you must be <a class=\"link\" href=\"/docs/12/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-CSVLOG\" title=\"19.8.4.\u00a0Using CSV-Format Log Output\">logging to a CSV file,</a> which here we will call <code class=\"literal\">pglog.csv</code>. First, install <code class=\"literal\">file_fdw</code> as an extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION file_fdw;\n</pre>\n<p>Then create a foreign server:</p>\n<pre class=\"programlisting\">CREATE SERVER pglog FOREIGN DATA WRAPPER file_fdw;\n</pre>\n<p>Now you are ready to create the foreign data table. Using the <code class=\"command\">CREATE FOREIGN TABLE</code> command, you will need to define the columns for the table, the CSV file name, and its format:</p>\n<pre class=\"programlisting\">CREATE FOREIGN TABLE pglog (\n  log_time timestamp(3) with time zone,\n  user_name text,\n  database_name text,\n  process_id integer,\n  connection_from text,\n  session_id text,\n  session_line_num bigint,\n  command_tag text,\n  session_start_time timestamp with time zone,\n  virtual_transaction_id text,\n  transaction_id bigint,\n  error_severity text,\n  sql_state_code text,\n  message text,\n  detail text,\n  hint text,\n  internal_query text,\n  internal_query_pos integer,\n  context text,\n  query text,\n  query_pos integer,\n  location text,\n  application_name text\n) SERVER pglog\nOPTIONS ( filename '/home/josh/data/log/pglog.csv', format 'csv' );\n</pre>\n<p>That's it \u2014 now you can query your log directly. In production, of course, you would need to define some way to deal with log rotation.</p>\n</div>\n</div><br class=\"example-break\">\n</div>", "manual_path": "/docs/12/file-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether the data has a header line, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "e3667962550d31793ff1cfb28056ac711b0cfd15ff9da272242f5b472d17c327", "runtime_verified": false}, "13": {"facts": [{"label": "Interface family", "value": "Foreign-data wrapper"}, {"label": "Handler or routine", "value": "file_fdw_handler"}, {"label": "Recorded callbacks", "value": "10"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "fileIterateForeignScan"}, {"state": "No handler registered in this build", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "Not registered"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether the data has a header line, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=13", "label": "Foreign-data wrapper catalog"}, {"url": "/e/file_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=13", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 13.23 source archive", "label": "13.23", "major": "13", "channel": "historical", "revision": "6ec3c82726af92b7dec873fa1cdf881eca92a4219787dfad05acb6b10e041fd6", "source_url": "https://ftp.postgresql.org/pub/source/v13.23/postgresql-13.23.tar.bz2", "source_snapshot_utc": ""}, "sources": [{"url": "/docs/13/file-fdw.html", "path": "file-fdw.html", "label": "PostgreSQL 13 English manual", "sha256": "879b7dc818754f3798684b46337ab1dd043e5dc5a2d144d4be2311ac8aa0be21"}, {"url": "https://ftp.postgresql.org/pub/source/v13.23/postgresql-13.23.tar.bz2", "line": 172, "path": "contrib/file_fdw/file_fdw.c", "label": "contrib/file_fdw/file_fdw.c:172", "sha256": "40594c4cbbae424ce0018f63b098c26a7b975a8ae4982d7cae481548d23c98d7", "archive_sha256": "6ec3c82726af92b7dec873fa1cdf881eca92a4219787dfad05acb6b10e041fd6"}], "sections": [{"title": "Interface and capability boundaries", "paragraphs": ["The matrix records callbacks actually registered in this source build. Registration identifies an implemented interface hook; options, query shape, privileges and provider rules determine whether an operation is allowed.", "The complete same-version manual below retains configuration, constraints and examples. No runtime capability test is claimed."]}, {"title": "File access boundary", "paragraphs": ["The file_fdw module provides the foreign-data wrapper file_fdw , which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by COPY FROM ; see COPY for details. Access to data files is currently read-only."]}, {"code": "{\n\tFdwRoutine *fdwroutine = makeNode(FdwRoutine);\n\n\tfdwroutine->GetForeignRelSize = fileGetForeignRelSize;\n\tfdwroutine->GetForeignPaths = fileGetForeignPaths;\n\tfdwroutine->GetForeignPlan = fileGetForeignPlan;\n\tfdwroutine->ExplainForeignScan = fileExplainForeignScan;\n\tfdwroutine->BeginForeignScan = fileBeginForeignScan;\n\tfdwroutine->IterateForeignScan = fileIterateForeignScan;\n\tfdwroutine->ReScanForeignScan = fileReScanForeignScan;\n\tfdwroutine->EndForeignScan = fileEndForeignScan;\n\tfdwroutine->AnalyzeForeignTable = fileAnalyzeForeignTable;\n\tfdwroutine->IsForeignScanParallelSafe = fileIsForeignScanParallelSafe;\n\n\tPG_RETURN_POINTER(fdwroutine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "description": ["Reads server-side files or program output through the foreign-data wrapper interface."], "manual_html": "<div class=\"sect1\" id=\"FILE-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.14.\u00a0file_fdw</h2>\n</div>\n</div>\n</div>\n<p>The <code class=\"filename\">file_fdw</code> module provides the foreign-data wrapper <code class=\"function\">file_fdw</code>, which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by <code class=\"command\">COPY FROM</code>; see <a class=\"xref\" href=\"/docs/13/sql-copy.html\" title=\"COPY\"><span class=\"refentrytitle\">COPY</span></a> for details. Access to data files is currently read-only.</p>\n<p>A foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">filename</code></span></dt>\n<dd>\n<p>Specifies the file to be read. Relative paths are relative to the data directory. Either <code class=\"literal\">filename</code> or <code class=\"literal\">program</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">program</code></span></dt>\n<dd>\n<p>Specifies the command to be executed. The standard output of this command will be read as though <code class=\"command\">COPY FROM PROGRAM</code> were used. Either <code class=\"literal\">program</code> or <code class=\"literal\">filename</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">format</code></span></dt>\n<dd>\n<p>Specifies the data format, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">FORMAT</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">header</code></span></dt>\n<dd>\n<p>Specifies whether the data has a header line, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">HEADER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">delimiter</code></span></dt>\n<dd>\n<p>Specifies the data delimiter character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">DELIMITER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">quote</code></span></dt>\n<dd>\n<p>Specifies the data quote character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">QUOTE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">escape</code></span></dt>\n<dd>\n<p>Specifies the data escape character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ESCAPE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">null</code></span></dt>\n<dd>\n<p>Specifies the data null string, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">encoding</code></span></dt>\n<dd>\n<p>Specifies the data encoding, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ENCODING</code> option.</p>\n</dd>\n</dl>\n</div>\n<p>Note that while <code class=\"command\">COPY</code> allows options such as <code class=\"literal\">HEADER</code> to be specified without a corresponding value, the foreign table option syntax requires a value to be present in all cases. To activate <code class=\"command\">COPY</code> options typically written without a value, you can pass the value TRUE, since all such options are Booleans.</p>\n<p>A column of a foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">force_not_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level <code class=\"literal\">null</code> option). This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NOT_NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">force_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as <code class=\"literal\">NULL</code> even if the value is quoted. Without this option, only unquoted values matching the null string are returned as <code class=\"literal\">NULL</code>. This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NULL</code> option.</p>\n</dd>\n</dl>\n</div>\n<p><code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_QUOTE</code> option is currently not supported by <code class=\"literal\">file_fdw</code>.</p>\n<p>These options can only be specified for a foreign table or its columns, not in the options of the <code class=\"literal\">file_fdw</code> foreign-data wrapper, nor in the options of a server or user mapping using the wrapper.</p>\n<p>Changing table-level options requires being a superuser or having the privileges of the default role <code class=\"literal\">pg_read_server_files</code> (to use a filename) or the default role <code class=\"literal\">pg_execute_server_program</code> (to use a program), for security reasons: only certain users should be able to control which file is read or which program is run. In principle regular users could be allowed to change the other options, but that's not supported at present.</p>\n<p>When specifying the <code class=\"literal\">program</code> option, keep in mind that the option string is executed by the shell. If you need to pass any arguments to the command that come from an untrusted source, you must be careful to strip or escape any characters that might have special meaning to the shell. For security reasons, it is best to use a fixed command string, or at least avoid passing any user input in it.</p>\n<p>For a foreign table using <code class=\"literal\">file_fdw</code>, <code class=\"command\">EXPLAIN</code> shows the name of the file to be read or program to be run. For a file, unless <code class=\"literal\">COSTS OFF</code> is specified, the file size (in bytes) is shown as well.</p>\n<div class=\"example\" id=\"id-1.11.7.23.14\">\n<p class=\"title\"><strong>Example\u00a0F.1.\u00a0Create a Foreign Table for PostgreSQL CSV Logs</strong></p>\n<div class=\"example-contents\">\n<p>One of the obvious uses for <code class=\"literal\">file_fdw</code> is to make the PostgreSQL activity log available as a table for querying. To do this, first you must be <a class=\"link\" href=\"/docs/13/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-CSVLOG\" title=\"19.8.4.\u00a0Using CSV-Format Log Output\">logging to a CSV file,</a> which here we will call <code class=\"literal\">pglog.csv</code>. First, install <code class=\"literal\">file_fdw</code> as an extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION file_fdw;\n</pre>\n<p>Then create a foreign server:</p>\n<pre class=\"programlisting\">CREATE SERVER pglog FOREIGN DATA WRAPPER file_fdw;\n</pre>\n<p>Now you are ready to create the foreign data table. Using the <code class=\"command\">CREATE FOREIGN TABLE</code> command, you will need to define the columns for the table, the CSV file name, and its format:</p>\n<pre class=\"programlisting\">CREATE FOREIGN TABLE pglog (\n  log_time timestamp(3) with time zone,\n  user_name text,\n  database_name text,\n  process_id integer,\n  connection_from text,\n  session_id text,\n  session_line_num bigint,\n  command_tag text,\n  session_start_time timestamp with time zone,\n  virtual_transaction_id text,\n  transaction_id bigint,\n  error_severity text,\n  sql_state_code text,\n  message text,\n  detail text,\n  hint text,\n  internal_query text,\n  internal_query_pos integer,\n  context text,\n  query text,\n  query_pos integer,\n  location text,\n  application_name text,\n  backend_type text\n) SERVER pglog\nOPTIONS ( filename 'log/pglog.csv', format 'csv' );\n</pre>\n<p>That's it \u2014 now you can query your log directly. In production, of course, you would need to define some way to deal with log rotation.</p>\n</div>\n</div><br class=\"example-break\">\n</div>", "manual_path": "/docs/13/file-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether the data has a header line, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "e3667962550d31793ff1cfb28056ac711b0cfd15ff9da272242f5b472d17c327", "runtime_verified": false}, "14": {"facts": [{"label": "Interface family", "value": "Foreign-data wrapper"}, {"label": "Handler or routine", "value": "file_fdw_handler"}, {"label": "Recorded callbacks", "value": "10"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "fileIterateForeignScan"}, {"state": "No handler registered in this build", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "Not registered"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether the data has a header line, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=14", "label": "Foreign-data wrapper catalog"}, {"url": "/e/file_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=14", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 14.24 source archive", "label": "14.24", "major": "14", "channel": "stable", "revision": "a7fa7ed3d558172355f51406097a7bd4f6b473be80f311ef7cda96bf383d8897", "source_url": "https://ftp.postgresql.org/pub/source/v14.24/postgresql-14.24.tar.bz2", "source_snapshot_utc": ""}, "sources": [{"url": "/docs/14/file-fdw.html", "path": "file-fdw.html", "label": "PostgreSQL 14 English manual", "sha256": "5f2338a8cfc33e89d34c5bf764b6aee9a1bac5a3b352094ed64df6cb1033eb76"}, {"url": "https://ftp.postgresql.org/pub/source/v14.24/postgresql-14.24.tar.bz2", "line": 172, "path": "contrib/file_fdw/file_fdw.c", "label": "contrib/file_fdw/file_fdw.c:172", "sha256": "fcd93dad4583cb3d29b4b02b002872fc6d5eab7ed6cc0c76e4a0293da819e5f2", "archive_sha256": "a7fa7ed3d558172355f51406097a7bd4f6b473be80f311ef7cda96bf383d8897"}], "sections": [{"title": "Interface and capability boundaries", "paragraphs": ["The matrix records callbacks actually registered in this source build. Registration identifies an implemented interface hook; options, query shape, privileges and provider rules determine whether an operation is allowed.", "The complete same-version manual below retains configuration, constraints and examples. No runtime capability test is claimed."]}, {"title": "File access boundary", "paragraphs": ["The file_fdw module provides the foreign-data wrapper file_fdw , which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by COPY FROM ; see COPY for details. Access to data files is currently read-only."]}, {"code": "{\n\tFdwRoutine *fdwroutine = makeNode(FdwRoutine);\n\n\tfdwroutine->GetForeignRelSize = fileGetForeignRelSize;\n\tfdwroutine->GetForeignPaths = fileGetForeignPaths;\n\tfdwroutine->GetForeignPlan = fileGetForeignPlan;\n\tfdwroutine->ExplainForeignScan = fileExplainForeignScan;\n\tfdwroutine->BeginForeignScan = fileBeginForeignScan;\n\tfdwroutine->IterateForeignScan = fileIterateForeignScan;\n\tfdwroutine->ReScanForeignScan = fileReScanForeignScan;\n\tfdwroutine->EndForeignScan = fileEndForeignScan;\n\tfdwroutine->AnalyzeForeignTable = fileAnalyzeForeignTable;\n\tfdwroutine->IsForeignScanParallelSafe = fileIsForeignScanParallelSafe;\n\n\tPG_RETURN_POINTER(fdwroutine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "description": ["Reads server-side files or program output through the foreign-data wrapper interface."], "manual_html": "<div class=\"sect1\" id=\"FILE-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.14.\u00a0file_fdw</h2>\n</div>\n</div>\n</div>\n<p>The <code class=\"filename\">file_fdw</code> module provides the foreign-data wrapper <code class=\"function\">file_fdw</code>, which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by <code class=\"command\">COPY FROM</code>; see <a class=\"xref\" href=\"/docs/14/sql-copy.html\" title=\"COPY\"><span class=\"refentrytitle\">COPY</span></a> for details. Access to data files is currently read-only.</p>\n<p>A foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">filename</code></span></dt>\n<dd>\n<p>Specifies the file to be read. Relative paths are relative to the data directory. Either <code class=\"literal\">filename</code> or <code class=\"literal\">program</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">program</code></span></dt>\n<dd>\n<p>Specifies the command to be executed. The standard output of this command will be read as though <code class=\"command\">COPY FROM PROGRAM</code> were used. Either <code class=\"literal\">program</code> or <code class=\"literal\">filename</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">format</code></span></dt>\n<dd>\n<p>Specifies the data format, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">FORMAT</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">header</code></span></dt>\n<dd>\n<p>Specifies whether the data has a header line, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">HEADER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">delimiter</code></span></dt>\n<dd>\n<p>Specifies the data delimiter character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">DELIMITER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">quote</code></span></dt>\n<dd>\n<p>Specifies the data quote character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">QUOTE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">escape</code></span></dt>\n<dd>\n<p>Specifies the data escape character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ESCAPE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">null</code></span></dt>\n<dd>\n<p>Specifies the data null string, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">encoding</code></span></dt>\n<dd>\n<p>Specifies the data encoding, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ENCODING</code> option.</p>\n</dd>\n</dl>\n</div>\n<p>Note that while <code class=\"command\">COPY</code> allows options such as <code class=\"literal\">HEADER</code> to be specified without a corresponding value, the foreign table option syntax requires a value to be present in all cases. To activate <code class=\"command\">COPY</code> options typically written without a value, you can pass the value TRUE, since all such options are Booleans.</p>\n<p>A column of a foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">force_not_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level <code class=\"literal\">null</code> option). This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NOT_NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">force_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as <code class=\"literal\">NULL</code> even if the value is quoted. Without this option, only unquoted values matching the null string are returned as <code class=\"literal\">NULL</code>. This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NULL</code> option.</p>\n</dd>\n</dl>\n</div>\n<p><code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_QUOTE</code> option is currently not supported by <code class=\"literal\">file_fdw</code>.</p>\n<p>These options can only be specified for a foreign table or its columns, not in the options of the <code class=\"literal\">file_fdw</code> foreign-data wrapper, nor in the options of a server or user mapping using the wrapper.</p>\n<p>Changing table-level options requires being a superuser or having the privileges of the role <code class=\"literal\">pg_read_server_files</code> (to use a filename) or the role <code class=\"literal\">pg_execute_server_program</code> (to use a program), for security reasons: only certain users should be able to control which file is read or which program is run. In principle regular users could be allowed to change the other options, but that's not supported at present.</p>\n<p>When specifying the <code class=\"literal\">program</code> option, keep in mind that the option string is executed by the shell. If you need to pass any arguments to the command that come from an untrusted source, you must be careful to strip or escape any characters that might have special meaning to the shell. For security reasons, it is best to use a fixed command string, or at least avoid passing any user input in it.</p>\n<p>For a foreign table using <code class=\"literal\">file_fdw</code>, <code class=\"command\">EXPLAIN</code> shows the name of the file to be read or program to be run. For a file, unless <code class=\"literal\">COSTS OFF</code> is specified, the file size (in bytes) is shown as well.</p>\n<div class=\"example\" id=\"id-1.11.7.23.14\">\n<p class=\"title\"><strong>Example\u00a0F.1.\u00a0Create a Foreign Table for PostgreSQL CSV Logs</strong></p>\n<div class=\"example-contents\">\n<p>One of the obvious uses for <code class=\"literal\">file_fdw</code> is to make the PostgreSQL activity log available as a table for querying. To do this, first you must be <a class=\"link\" href=\"/docs/14/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-CSVLOG\" title=\"20.8.4.\u00a0Using CSV-Format Log Output\">logging to a CSV file,</a> which here we will call <code class=\"literal\">pglog.csv</code>. First, install <code class=\"literal\">file_fdw</code> as an extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION file_fdw;\n</pre>\n<p>Then create a foreign server:</p>\n<pre class=\"programlisting\">CREATE SERVER pglog FOREIGN DATA WRAPPER file_fdw;\n</pre>\n<p>Now you are ready to create the foreign data table. Using the <code class=\"command\">CREATE FOREIGN TABLE</code> command, you will need to define the columns for the table, the CSV file name, and its format:</p>\n<pre class=\"programlisting\">CREATE FOREIGN TABLE pglog (\n  log_time timestamp(3) with time zone,\n  user_name text,\n  database_name text,\n  process_id integer,\n  connection_from text,\n  session_id text,\n  session_line_num bigint,\n  command_tag text,\n  session_start_time timestamp with time zone,\n  virtual_transaction_id text,\n  transaction_id bigint,\n  error_severity text,\n  sql_state_code text,\n  message text,\n  detail text,\n  hint text,\n  internal_query text,\n  internal_query_pos integer,\n  context text,\n  query text,\n  query_pos integer,\n  location text,\n  application_name text,\n  backend_type text,\n  leader_pid integer,\n  query_id bigint\n) SERVER pglog\nOPTIONS ( filename 'log/pglog.csv', format 'csv' );\n</pre>\n<p>That's it \u2014 now you can query your log directly. In production, of course, you would need to define some way to deal with log rotation.</p>\n</div>\n</div><br class=\"example-break\">\n</div>", "manual_path": "/docs/14/file-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether the data has a header line, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "e3667962550d31793ff1cfb28056ac711b0cfd15ff9da272242f5b472d17c327", "runtime_verified": false}, "15": {"facts": [{"label": "Interface family", "value": "Foreign-data wrapper"}, {"label": "Handler or routine", "value": "file_fdw_handler"}, {"label": "Recorded callbacks", "value": "10"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "fileIterateForeignScan"}, {"state": "No handler registered in this build", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "Not registered"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether the data has a header line, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=15", "label": "Foreign-data wrapper catalog"}, {"url": "/e/file_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=15", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 15.19 source archive", "label": "15.19", "major": "15", "channel": "stable", "revision": "e1a64a87a46b825b88c082e4518161a47aab53c45694964f8ba1df28f7859f89", "source_url": "https://ftp.postgresql.org/pub/source/v15.19/postgresql-15.19.tar.bz2", "source_snapshot_utc": ""}, "sources": [{"url": "/docs/15/file-fdw.html", "path": "file-fdw.html", "label": "PostgreSQL 15 English manual", "sha256": "a4c229bbafc6b16e98525250700926b2aff4e8a56419b0fa836773f509bf4c1e"}, {"url": "https://ftp.postgresql.org/pub/source/v15.19/postgresql-15.19.tar.bz2", "line": 172, "path": "contrib/file_fdw/file_fdw.c", "label": "contrib/file_fdw/file_fdw.c:172", "sha256": "ae6742d752f167ba254c82fe57b6dca11653e4a04b753f494981ca4b9293bb83", "archive_sha256": "e1a64a87a46b825b88c082e4518161a47aab53c45694964f8ba1df28f7859f89"}], "sections": [{"title": "Interface and capability boundaries", "paragraphs": ["The matrix records callbacks actually registered in this source build. Registration identifies an implemented interface hook; options, query shape, privileges and provider rules determine whether an operation is allowed.", "The complete same-version manual below retains configuration, constraints and examples. No runtime capability test is claimed."]}, {"title": "File access boundary", "paragraphs": ["The file_fdw module provides the foreign-data wrapper file_fdw , which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by COPY FROM ; see COPY for details. Access to data files is currently read-only."]}, {"code": "{\n\tFdwRoutine *fdwroutine = makeNode(FdwRoutine);\n\n\tfdwroutine->GetForeignRelSize = fileGetForeignRelSize;\n\tfdwroutine->GetForeignPaths = fileGetForeignPaths;\n\tfdwroutine->GetForeignPlan = fileGetForeignPlan;\n\tfdwroutine->ExplainForeignScan = fileExplainForeignScan;\n\tfdwroutine->BeginForeignScan = fileBeginForeignScan;\n\tfdwroutine->IterateForeignScan = fileIterateForeignScan;\n\tfdwroutine->ReScanForeignScan = fileReScanForeignScan;\n\tfdwroutine->EndForeignScan = fileEndForeignScan;\n\tfdwroutine->AnalyzeForeignTable = fileAnalyzeForeignTable;\n\tfdwroutine->IsForeignScanParallelSafe = fileIsForeignScanParallelSafe;\n\n\tPG_RETURN_POINTER(fdwroutine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "description": ["Reads server-side files or program output through the foreign-data wrapper interface."], "manual_html": "<div class=\"sect1\" id=\"FILE-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.16.\u00a0file_fdw</h2>\n</div>\n</div>\n</div>\n<p>The <code class=\"filename\">file_fdw</code> module provides the foreign-data wrapper <code class=\"function\">file_fdw</code>, which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by <code class=\"command\">COPY FROM</code>; see <a class=\"xref\" href=\"/docs/15/sql-copy.html\" title=\"COPY\"><span class=\"refentrytitle\">COPY</span></a> for details. Access to data files is currently read-only.</p>\n<p>A foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">filename</code></span></dt>\n<dd>\n<p>Specifies the file to be read. Relative paths are relative to the data directory. Either <code class=\"literal\">filename</code> or <code class=\"literal\">program</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">program</code></span></dt>\n<dd>\n<p>Specifies the command to be executed. The standard output of this command will be read as though <code class=\"command\">COPY FROM PROGRAM</code> were used. Either <code class=\"literal\">program</code> or <code class=\"literal\">filename</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">format</code></span></dt>\n<dd>\n<p>Specifies the data format, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">FORMAT</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">header</code></span></dt>\n<dd>\n<p>Specifies whether the data has a header line, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">HEADER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">delimiter</code></span></dt>\n<dd>\n<p>Specifies the data delimiter character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">DELIMITER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">quote</code></span></dt>\n<dd>\n<p>Specifies the data quote character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">QUOTE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">escape</code></span></dt>\n<dd>\n<p>Specifies the data escape character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ESCAPE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">null</code></span></dt>\n<dd>\n<p>Specifies the data null string, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">encoding</code></span></dt>\n<dd>\n<p>Specifies the data encoding, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ENCODING</code> option.</p>\n</dd>\n</dl>\n</div>\n<p>Note that while <code class=\"command\">COPY</code> allows options such as <code class=\"literal\">HEADER</code> to be specified without a corresponding value, the foreign table option syntax requires a value to be present in all cases. To activate <code class=\"command\">COPY</code> options typically written without a value, you can pass the value TRUE, since all such options are Booleans.</p>\n<p>A column of a foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">force_not_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level <code class=\"literal\">null</code> option). This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NOT_NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">force_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as <code class=\"literal\">NULL</code> even if the value is quoted. Without this option, only unquoted values matching the null string are returned as <code class=\"literal\">NULL</code>. This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NULL</code> option.</p>\n</dd>\n</dl>\n</div>\n<p><code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_QUOTE</code> option is currently not supported by <code class=\"literal\">file_fdw</code>.</p>\n<p>These options can only be specified for a foreign table or its columns, not in the options of the <code class=\"literal\">file_fdw</code> foreign-data wrapper, nor in the options of a server or user mapping using the wrapper.</p>\n<p>Changing table-level options requires being a superuser or having the privileges of the role <code class=\"literal\">pg_read_server_files</code> (to use a filename) or the role <code class=\"literal\">pg_execute_server_program</code> (to use a program), for security reasons: only certain users should be able to control which file is read or which program is run. In principle regular users could be allowed to change the other options, but that's not supported at present.</p>\n<p>When specifying the <code class=\"literal\">program</code> option, keep in mind that the option string is executed by the shell. If you need to pass any arguments to the command that come from an untrusted source, you must be careful to strip or escape any characters that might have special meaning to the shell. For security reasons, it is best to use a fixed command string, or at least avoid passing any user input in it.</p>\n<p>For a foreign table using <code class=\"literal\">file_fdw</code>, <code class=\"command\">EXPLAIN</code> shows the name of the file to be read or program to be run. For a file, unless <code class=\"literal\">COSTS OFF</code> is specified, the file size (in bytes) is shown as well.</p>\n<div class=\"example\" id=\"id-1.11.7.25.14\">\n<p class=\"title\"><strong>Example\u00a0F.1.\u00a0Create a Foreign Table for PostgreSQL CSV Logs</strong></p>\n<div class=\"example-contents\">\n<p>One of the obvious uses for <code class=\"literal\">file_fdw</code> is to make the PostgreSQL activity log available as a table for querying. To do this, first you must be <a class=\"link\" href=\"/docs/15/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-CSVLOG\" title=\"20.8.4.\u00a0Using CSV-Format Log Output\">logging to a CSV file,</a> which here we will call <code class=\"literal\">pglog.csv</code>. First, install <code class=\"literal\">file_fdw</code> as an extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION file_fdw;\n</pre>\n<p>Then create a foreign server:</p>\n<pre class=\"programlisting\">CREATE SERVER pglog FOREIGN DATA WRAPPER file_fdw;\n</pre>\n<p>Now you are ready to create the foreign data table. Using the <code class=\"command\">CREATE FOREIGN TABLE</code> command, you will need to define the columns for the table, the CSV file name, and its format:</p>\n<pre class=\"programlisting\">CREATE FOREIGN TABLE pglog (\n  log_time timestamp(3) with time zone,\n  user_name text,\n  database_name text,\n  process_id integer,\n  connection_from text,\n  session_id text,\n  session_line_num bigint,\n  command_tag text,\n  session_start_time timestamp with time zone,\n  virtual_transaction_id text,\n  transaction_id bigint,\n  error_severity text,\n  sql_state_code text,\n  message text,\n  detail text,\n  hint text,\n  internal_query text,\n  internal_query_pos integer,\n  context text,\n  query text,\n  query_pos integer,\n  location text,\n  application_name text,\n  backend_type text,\n  leader_pid integer,\n  query_id bigint\n) SERVER pglog\nOPTIONS ( filename 'log/pglog.csv', format 'csv' );\n</pre>\n<p>That's it \u2014 now you can query your log directly. In production, of course, you would need to define some way to deal with log rotation.</p>\n</div>\n</div><br class=\"example-break\">\n</div>", "manual_path": "/docs/15/file-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether the data has a header line, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "e3667962550d31793ff1cfb28056ac711b0cfd15ff9da272242f5b472d17c327", "runtime_verified": false}, "16": {"facts": [{"label": "Interface family", "value": "Foreign-data wrapper"}, {"label": "Handler or routine", "value": "file_fdw_handler"}, {"label": "Recorded callbacks", "value": "10"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "fileIterateForeignScan"}, {"state": "No handler registered in this build", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "Not registered"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether the data has a header line, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "default", "definition": "Specifies the string that represents a default value, the same as COPY 's DEFAULT option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=16", "label": "Foreign-data wrapper catalog"}, {"url": "/e/file_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=16", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 16.15 source archive", "label": "16.15", "major": "16", "channel": "stable", "revision": "c1575341fa7bd40f5274ea465b34390f4dc64cdd0770af327005caaeb9f6b7ed", "source_url": "https://ftp.postgresql.org/pub/source/v16.15/postgresql-16.15.tar.bz2", "source_snapshot_utc": ""}, "sources": [{"url": "/docs/16/file-fdw.html", "path": "file-fdw.html", "label": "PostgreSQL 16 English manual", "sha256": "600f45273de1cab3a84df14cff52f13be80dc82c8dd7848989a4beb2c8e92d15"}, {"url": "https://ftp.postgresql.org/pub/source/v16.15/postgresql-16.15.tar.bz2", "line": 174, "path": "contrib/file_fdw/file_fdw.c", "label": "contrib/file_fdw/file_fdw.c:174", "sha256": "b545acfbffc7191a48bdf1364e68530531c4e24e06cd5bd7576732e76c6ad63f", "archive_sha256": "c1575341fa7bd40f5274ea465b34390f4dc64cdd0770af327005caaeb9f6b7ed"}], "sections": [{"title": "Interface and capability boundaries", "paragraphs": ["The matrix records callbacks actually registered in this source build. Registration identifies an implemented interface hook; options, query shape, privileges and provider rules determine whether an operation is allowed.", "The complete same-version manual below retains configuration, constraints and examples. No runtime capability test is claimed."]}, {"title": "File access boundary", "paragraphs": ["The file_fdw module provides the foreign-data wrapper file_fdw , which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by COPY FROM ; see COPY for details. Access to data files is currently read-only."]}, {"code": "{\n\tFdwRoutine *fdwroutine = makeNode(FdwRoutine);\n\n\tfdwroutine->GetForeignRelSize = fileGetForeignRelSize;\n\tfdwroutine->GetForeignPaths = fileGetForeignPaths;\n\tfdwroutine->GetForeignPlan = fileGetForeignPlan;\n\tfdwroutine->ExplainForeignScan = fileExplainForeignScan;\n\tfdwroutine->BeginForeignScan = fileBeginForeignScan;\n\tfdwroutine->IterateForeignScan = fileIterateForeignScan;\n\tfdwroutine->ReScanForeignScan = fileReScanForeignScan;\n\tfdwroutine->EndForeignScan = fileEndForeignScan;\n\tfdwroutine->AnalyzeForeignTable = fileAnalyzeForeignTable;\n\tfdwroutine->IsForeignScanParallelSafe = fileIsForeignScanParallelSafe;\n\n\tPG_RETURN_POINTER(fdwroutine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "description": ["Reads server-side files or program output through the foreign-data wrapper interface."], "manual_html": "<div class=\"sect1\" id=\"FILE-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.16.\u00a0file_fdw \u2014 access data files in the server's file system </h2>\n</div>\n</div>\n</div>\n<p>The <code class=\"filename\">file_fdw</code> module provides the foreign-data wrapper <code class=\"function\">file_fdw</code>, which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by <code class=\"command\">COPY FROM</code>; see <a class=\"xref\" href=\"/docs/16/sql-copy.html\" title=\"COPY\"><span class=\"refentrytitle\">COPY</span></a> for details. Access to data files is currently read-only.</p>\n<p>A foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">filename</code></span></dt>\n<dd>\n<p>Specifies the file to be read. Relative paths are relative to the data directory. Either <code class=\"literal\">filename</code> or <code class=\"literal\">program</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">program</code></span></dt>\n<dd>\n<p>Specifies the command to be executed. The standard output of this command will be read as though <code class=\"command\">COPY FROM PROGRAM</code> were used. Either <code class=\"literal\">program</code> or <code class=\"literal\">filename</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">format</code></span></dt>\n<dd>\n<p>Specifies the data format, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">FORMAT</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">header</code></span></dt>\n<dd>\n<p>Specifies whether the data has a header line, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">HEADER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">delimiter</code></span></dt>\n<dd>\n<p>Specifies the data delimiter character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">DELIMITER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">quote</code></span></dt>\n<dd>\n<p>Specifies the data quote character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">QUOTE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">escape</code></span></dt>\n<dd>\n<p>Specifies the data escape character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ESCAPE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">null</code></span></dt>\n<dd>\n<p>Specifies the data null string, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">default</code></span></dt>\n<dd>\n<p>Specifies the string that represents a default value, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">DEFAULT</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">encoding</code></span></dt>\n<dd>\n<p>Specifies the data encoding, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ENCODING</code> option.</p>\n</dd>\n</dl>\n</div>\n<p>Note that while <code class=\"command\">COPY</code> allows options such as <code class=\"literal\">HEADER</code> to be specified without a corresponding value, the foreign table option syntax requires a value to be present in all cases. To activate <code class=\"command\">COPY</code> options typically written without a value, you can pass the value TRUE, since all such options are Booleans.</p>\n<p>A column of a foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">force_not_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level <code class=\"literal\">null</code> option). This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NOT_NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">force_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as <code class=\"literal\">NULL</code> even if the value is quoted. Without this option, only unquoted values matching the null string are returned as <code class=\"literal\">NULL</code>. This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NULL</code> option.</p>\n</dd>\n</dl>\n</div>\n<p><code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_QUOTE</code> option is currently not supported by <code class=\"literal\">file_fdw</code>.</p>\n<p>These options can only be specified for a foreign table or its columns, not in the options of the <code class=\"literal\">file_fdw</code> foreign-data wrapper, nor in the options of a server or user mapping using the wrapper.</p>\n<p>Changing table-level options requires being a superuser or having the privileges of the role <code class=\"literal\">pg_read_server_files</code> (to use a filename) or the role <code class=\"literal\">pg_execute_server_program</code> (to use a program), for security reasons: only certain users should be able to control which file is read or which program is run. In principle regular users could be allowed to change the other options, but that's not supported at present.</p>\n<p>When specifying the <code class=\"literal\">program</code> option, keep in mind that the option string is executed by the shell. If you need to pass any arguments to the command that come from an untrusted source, you must be careful to strip or escape any characters that might have special meaning to the shell. For security reasons, it is best to use a fixed command string, or at least avoid passing any user input in it.</p>\n<p>For a foreign table using <code class=\"literal\">file_fdw</code>, <code class=\"command\">EXPLAIN</code> shows the name of the file to be read or program to be run. For a file, unless <code class=\"literal\">COSTS OFF</code> is specified, the file size (in bytes) is shown as well.</p>\n<div class=\"example\" id=\"id-1.11.7.26.14\">\n<p class=\"title\"><strong>Example\u00a0F.1.\u00a0Create a Foreign Table for PostgreSQL CSV Logs</strong></p>\n<div class=\"example-contents\">\n<p>One of the obvious uses for <code class=\"literal\">file_fdw</code> is to make the PostgreSQL activity log available as a table for querying. To do this, first you must be <a class=\"link\" href=\"/docs/16/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-CSVLOG\" title=\"20.8.4.\u00a0Using CSV-Format Log Output\">logging to a CSV file,</a> which here we will call <code class=\"literal\">pglog.csv</code>. First, install <code class=\"literal\">file_fdw</code> as an extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION file_fdw;\n</pre>\n<p>Then create a foreign server:</p>\n<pre class=\"programlisting\">CREATE SERVER pglog FOREIGN DATA WRAPPER file_fdw;\n</pre>\n<p>Now you are ready to create the foreign data table. Using the <code class=\"command\">CREATE FOREIGN TABLE</code> command, you will need to define the columns for the table, the CSV file name, and its format:</p>\n<pre class=\"programlisting\">CREATE FOREIGN TABLE pglog (\n  log_time timestamp(3) with time zone,\n  user_name text,\n  database_name text,\n  process_id integer,\n  connection_from text,\n  session_id text,\n  session_line_num bigint,\n  command_tag text,\n  session_start_time timestamp with time zone,\n  virtual_transaction_id text,\n  transaction_id bigint,\n  error_severity text,\n  sql_state_code text,\n  message text,\n  detail text,\n  hint text,\n  internal_query text,\n  internal_query_pos integer,\n  context text,\n  query text,\n  query_pos integer,\n  location text,\n  application_name text,\n  backend_type text,\n  leader_pid integer,\n  query_id bigint\n) SERVER pglog\nOPTIONS ( filename 'log/pglog.csv', format 'csv' );\n</pre>\n<p>That's it \u2014 now you can query your log directly. In production, of course, you would need to define some way to deal with log rotation.</p>\n</div>\n</div><br class=\"example-break\">\n</div>", "manual_path": "/docs/16/file-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether the data has a header line, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "default", "definition": "Specifies the string that represents a default value, the same as COPY 's DEFAULT option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "ec8801ddff287a4296f6ec9e1e66865681d20d3b9e524553fc6caf16973011bd", "runtime_verified": false}, "17": {"facts": [{"label": "Interface family", "value": "Foreign-data wrapper"}, {"label": "Handler or routine", "value": "file_fdw_handler"}, {"label": "Recorded callbacks", "value": "10"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "fileIterateForeignScan"}, {"state": "No handler registered in this build", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "Not registered"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether the data has a header line, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "default", "definition": "Specifies the string that represents a default value, the same as COPY 's DEFAULT option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=17", "label": "Foreign-data wrapper catalog"}, {"url": "/e/file_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=17", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 17.11 source archive", "label": "17.11", "major": "17", "channel": "stable", "revision": "dd27f2b3c59e73ed14aa3324901242bf69a032a6347805f274e6260322d42979", "source_url": "https://ftp.postgresql.org/pub/source/v17.11/postgresql-17.11.tar.bz2", "source_snapshot_utc": ""}, "sources": [{"url": "/docs/17/file-fdw.html", "path": "file-fdw.html", "label": "PostgreSQL 17 English manual", "sha256": "91d02e8e196428b1e6ab1eea2547f1e746ef2aad63e5a1e613d2efad536658ad"}, {"url": "https://ftp.postgresql.org/pub/source/v17.11/postgresql-17.11.tar.bz2", "line": 174, "path": "contrib/file_fdw/file_fdw.c", "label": "contrib/file_fdw/file_fdw.c:174", "sha256": "35aff72d3d675e07289b3e6f9b9c7b062b02133cb8de67efacd297258b80ad22", "archive_sha256": "dd27f2b3c59e73ed14aa3324901242bf69a032a6347805f274e6260322d42979"}], "sections": [{"title": "Interface and capability boundaries", "paragraphs": ["The matrix records callbacks actually registered in this source build. Registration identifies an implemented interface hook; options, query shape, privileges and provider rules determine whether an operation is allowed.", "The complete same-version manual below retains configuration, constraints and examples. No runtime capability test is claimed."]}, {"title": "File access boundary", "paragraphs": ["The file_fdw module provides the foreign-data wrapper file_fdw , which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by COPY FROM ; see COPY for details. Access to data files is currently read-only."]}, {"code": "{\n\tFdwRoutine *fdwroutine = makeNode(FdwRoutine);\n\n\tfdwroutine->GetForeignRelSize = fileGetForeignRelSize;\n\tfdwroutine->GetForeignPaths = fileGetForeignPaths;\n\tfdwroutine->GetForeignPlan = fileGetForeignPlan;\n\tfdwroutine->ExplainForeignScan = fileExplainForeignScan;\n\tfdwroutine->BeginForeignScan = fileBeginForeignScan;\n\tfdwroutine->IterateForeignScan = fileIterateForeignScan;\n\tfdwroutine->ReScanForeignScan = fileReScanForeignScan;\n\tfdwroutine->EndForeignScan = fileEndForeignScan;\n\tfdwroutine->AnalyzeForeignTable = fileAnalyzeForeignTable;\n\tfdwroutine->IsForeignScanParallelSafe = fileIsForeignScanParallelSafe;\n\n\tPG_RETURN_POINTER(fdwroutine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "description": ["Reads server-side files or program output through the foreign-data wrapper interface."], "manual_html": "<div class=\"sect1\" id=\"FILE-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.15.\u00a0file_fdw \u2014 access data files in the server's file system </h2>\n</div>\n</div>\n</div>\n<p>The <code class=\"filename\">file_fdw</code> module provides the foreign-data wrapper <code class=\"function\">file_fdw</code>, which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by <code class=\"command\">COPY FROM</code>; see <a class=\"xref\" href=\"/docs/17/sql-copy.html\" title=\"COPY\"><span class=\"refentrytitle\">COPY</span></a> for details. Access to data files is currently read-only.</p>\n<p>A foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">filename</code></span></dt>\n<dd>\n<p>Specifies the file to be read. Relative paths are relative to the data directory. Either <code class=\"literal\">filename</code> or <code class=\"literal\">program</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">program</code></span></dt>\n<dd>\n<p>Specifies the command to be executed. The standard output of this command will be read as though <code class=\"command\">COPY FROM PROGRAM</code> were used. Either <code class=\"literal\">program</code> or <code class=\"literal\">filename</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">format</code></span></dt>\n<dd>\n<p>Specifies the data format, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">FORMAT</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">header</code></span></dt>\n<dd>\n<p>Specifies whether the data has a header line, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">HEADER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">delimiter</code></span></dt>\n<dd>\n<p>Specifies the data delimiter character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">DELIMITER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">quote</code></span></dt>\n<dd>\n<p>Specifies the data quote character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">QUOTE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">escape</code></span></dt>\n<dd>\n<p>Specifies the data escape character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ESCAPE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">null</code></span></dt>\n<dd>\n<p>Specifies the data null string, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">default</code></span></dt>\n<dd>\n<p>Specifies the string that represents a default value, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">DEFAULT</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">encoding</code></span></dt>\n<dd>\n<p>Specifies the data encoding, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ENCODING</code> option.</p>\n</dd>\n</dl>\n</div>\n<p>Note that while <code class=\"command\">COPY</code> allows options such as <code class=\"literal\">HEADER</code> to be specified without a corresponding value, the foreign table option syntax requires a value to be present in all cases. To activate <code class=\"command\">COPY</code> options typically written without a value, you can pass the value TRUE, since all such options are Booleans.</p>\n<p>A column of a foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">force_not_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level <code class=\"literal\">null</code> option). This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NOT_NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">force_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as <code class=\"literal\">NULL</code> even if the value is quoted. Without this option, only unquoted values matching the null string are returned as <code class=\"literal\">NULL</code>. This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NULL</code> option.</p>\n</dd>\n</dl>\n</div>\n<p><code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_QUOTE</code> option is currently not supported by <code class=\"literal\">file_fdw</code>.</p>\n<p>These options can only be specified for a foreign table or its columns, not in the options of the <code class=\"literal\">file_fdw</code> foreign-data wrapper, nor in the options of a server or user mapping using the wrapper.</p>\n<p>Changing table-level options requires being a superuser or having the privileges of the role <code class=\"literal\">pg_read_server_files</code> (to use a filename) or the role <code class=\"literal\">pg_execute_server_program</code> (to use a program), for security reasons: only certain users should be able to control which file is read or which program is run. In principle regular users could be allowed to change the other options, but that's not supported at present.</p>\n<p>When specifying the <code class=\"literal\">program</code> option, keep in mind that the option string is executed by the shell. If you need to pass any arguments to the command that come from an untrusted source, you must be careful to strip or escape any characters that might have special meaning to the shell. For security reasons, it is best to use a fixed command string, or at least avoid passing any user input in it.</p>\n<p>For a foreign table using <code class=\"literal\">file_fdw</code>, <code class=\"command\">EXPLAIN</code> shows the name of the file to be read or program to be run. For a file, unless <code class=\"literal\">COSTS OFF</code> is specified, the file size (in bytes) is shown as well.</p>\n<div class=\"example\" id=\"id-1.11.7.25.14\">\n<p class=\"title\"><strong>Example\u00a0F.1.\u00a0Create a Foreign Table for PostgreSQL CSV Logs</strong></p>\n<div class=\"example-contents\">\n<p>One of the obvious uses for <code class=\"literal\">file_fdw</code> is to make the PostgreSQL activity log available as a table for querying. To do this, first you must be <a class=\"link\" href=\"/docs/17/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-CSVLOG\" title=\"19.8.4.\u00a0Using CSV-Format Log Output\">logging to a CSV file,</a> which here we will call <code class=\"literal\">pglog.csv</code>. First, install <code class=\"literal\">file_fdw</code> as an extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION file_fdw;\n</pre>\n<p>Then create a foreign server:</p>\n<pre class=\"programlisting\">CREATE SERVER pglog FOREIGN DATA WRAPPER file_fdw;\n</pre>\n<p>Now you are ready to create the foreign data table. Using the <code class=\"command\">CREATE FOREIGN TABLE</code> command, you will need to define the columns for the table, the CSV file name, and its format:</p>\n<pre class=\"programlisting\">CREATE FOREIGN TABLE pglog (\n  log_time timestamp(3) with time zone,\n  user_name text,\n  database_name text,\n  process_id integer,\n  connection_from text,\n  session_id text,\n  session_line_num bigint,\n  command_tag text,\n  session_start_time timestamp with time zone,\n  virtual_transaction_id text,\n  transaction_id bigint,\n  error_severity text,\n  sql_state_code text,\n  message text,\n  detail text,\n  hint text,\n  internal_query text,\n  internal_query_pos integer,\n  context text,\n  query text,\n  query_pos integer,\n  location text,\n  application_name text,\n  backend_type text,\n  leader_pid integer,\n  query_id bigint\n) SERVER pglog\nOPTIONS ( filename 'log/pglog.csv', format 'csv' );\n</pre>\n<p>That's it \u2014 now you can query your log directly. In production, of course, you would need to define some way to deal with log rotation.</p>\n</div>\n</div><br class=\"example-break\">\n<div class=\"example\" id=\"id-1.11.7.25.15\">\n<p class=\"title\"><strong>Example\u00a0F.2.\u00a0Create a Foreign Table with an Option on a Column</strong></p>\n<div class=\"example-contents\">\n<p>To set the <code class=\"literal\">force_null</code> option for a column, use the <code class=\"literal\">OPTIONS</code> keyword.</p>\n<pre class=\"programlisting\">CREATE FOREIGN TABLE films (\n code char(5) NOT NULL,\n title text NOT NULL,\n rating text OPTIONS (force_null 'true')\n) SERVER film_server\nOPTIONS ( filename 'films/db.csv', format 'csv' );\n</pre>\n</div>\n</div><br class=\"example-break\">\n</div>", "manual_path": "/docs/17/file-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether the data has a header line, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "default", "definition": "Specifies the string that represents a default value, the same as COPY 's DEFAULT option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "ec8801ddff287a4296f6ec9e1e66865681d20d3b9e524553fc6caf16973011bd", "runtime_verified": false}, "18": {"facts": [{"label": "Interface family", "value": "Foreign-data wrapper"}, {"label": "Handler or routine", "value": "file_fdw_handler"}, {"label": "Recorded callbacks", "value": "10"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "fileIterateForeignScan"}, {"state": "No handler registered in this build", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "Not registered"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether the data has a header line, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "default", "definition": "Specifies the string that represents a default value, the same as COPY 's DEFAULT option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "on_error", "definition": "Specifies how to behave when encountering an error converting a column's input value into its data type, the same as COPY 's ON_ERROR option."}, {"name": "reject_limit", "definition": "Specifies the maximum number of errors tolerated while converting a column's input value to its data type, the same as COPY 's REJECT_LIMIT option."}, {"name": "log_verbosity", "definition": "Specifies the amount of messages emitted by file_fdw , the same as COPY 's LOG_VERBOSITY option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=18", "label": "Foreign-data wrapper catalog"}, {"url": "/e/file_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=18", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 18.6 source archive", "label": "18.6", "major": "18", "channel": "stable", "revision": "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f", "source_url": "https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2", "source_snapshot_utc": ""}, "sources": [{"url": "/docs/18/file-fdw.html", "path": "file-fdw.html", "label": "PostgreSQL 18 English manual", "sha256": "5da35cee02e73ec6656a2020d8351046cad9283a137b45064bee58f1ff7eb787"}, {"url": "https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2", "line": 183, "path": "contrib/file_fdw/file_fdw.c", "label": "contrib/file_fdw/file_fdw.c:183", "sha256": "d79ec21c08be6a806b0710aab09698678ddb24103d3470702e66ee1523432125", "archive_sha256": "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"}], "sections": [{"title": "Interface and capability boundaries", "paragraphs": ["The matrix records callbacks actually registered in this source build. Registration identifies an implemented interface hook; options, query shape, privileges and provider rules determine whether an operation is allowed.", "The complete same-version manual below retains configuration, constraints and examples. No runtime capability test is claimed."]}, {"title": "File access boundary", "paragraphs": ["The file_fdw module provides the foreign-data wrapper file_fdw , which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by COPY FROM ; see COPY for details. Access to data files is currently read-only."]}, {"code": "{\n\tFdwRoutine *fdwroutine = makeNode(FdwRoutine);\n\n\tfdwroutine->GetForeignRelSize = fileGetForeignRelSize;\n\tfdwroutine->GetForeignPaths = fileGetForeignPaths;\n\tfdwroutine->GetForeignPlan = fileGetForeignPlan;\n\tfdwroutine->ExplainForeignScan = fileExplainForeignScan;\n\tfdwroutine->BeginForeignScan = fileBeginForeignScan;\n\tfdwroutine->IterateForeignScan = fileIterateForeignScan;\n\tfdwroutine->ReScanForeignScan = fileReScanForeignScan;\n\tfdwroutine->EndForeignScan = fileEndForeignScan;\n\tfdwroutine->AnalyzeForeignTable = fileAnalyzeForeignTable;\n\tfdwroutine->IsForeignScanParallelSafe = fileIsForeignScanParallelSafe;\n\n\tPG_RETURN_POINTER(fdwroutine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "description": ["Reads server-side files or program output through the foreign-data wrapper interface."], "manual_html": "<div class=\"sect1\" id=\"FILE-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.15.\u00a0file_fdw \u2014 access data files in the server's file system </h2>\n</div>\n</div>\n</div>\n<p>The <code class=\"filename\">file_fdw</code> module provides the foreign-data wrapper <code class=\"function\">file_fdw</code>, which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by <code class=\"command\">COPY FROM</code>; see <a class=\"xref\" href=\"/docs/18/sql-copy.html\" title=\"COPY\"><span class=\"refentrytitle\">COPY</span></a> for details. Access to data files is currently read-only.</p>\n<p>A foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">filename</code></span></dt>\n<dd>\n<p>Specifies the file to be read. Relative paths are relative to the data directory. Either <code class=\"literal\">filename</code> or <code class=\"literal\">program</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">program</code></span></dt>\n<dd>\n<p>Specifies the command to be executed. The standard output of this command will be read as though <code class=\"command\">COPY FROM PROGRAM</code> were used. Either <code class=\"literal\">program</code> or <code class=\"literal\">filename</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">format</code></span></dt>\n<dd>\n<p>Specifies the data format, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">FORMAT</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">header</code></span></dt>\n<dd>\n<p>Specifies whether the data has a header line, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">HEADER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">delimiter</code></span></dt>\n<dd>\n<p>Specifies the data delimiter character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">DELIMITER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">quote</code></span></dt>\n<dd>\n<p>Specifies the data quote character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">QUOTE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">escape</code></span></dt>\n<dd>\n<p>Specifies the data escape character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ESCAPE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">null</code></span></dt>\n<dd>\n<p>Specifies the data null string, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">default</code></span></dt>\n<dd>\n<p>Specifies the string that represents a default value, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">DEFAULT</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">encoding</code></span></dt>\n<dd>\n<p>Specifies the data encoding, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ENCODING</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">on_error</code></span></dt>\n<dd>\n<p>Specifies how to behave when encountering an error converting a column's input value into its data type, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ON_ERROR</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">reject_limit</code></span></dt>\n<dd>\n<p>Specifies the maximum number of errors tolerated while converting a column's input value to its data type, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">REJECT_LIMIT</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">log_verbosity</code></span></dt>\n<dd>\n<p>Specifies the amount of messages emitted by <code class=\"literal\">file_fdw</code>, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">LOG_VERBOSITY</code> option.</p>\n</dd>\n</dl>\n</div>\n<p>Note that while <code class=\"command\">COPY</code> allows options such as <code class=\"literal\">HEADER</code> to be specified without a corresponding value, the foreign table option syntax requires a value to be present in all cases. To activate <code class=\"command\">COPY</code> options typically written without a value, you can pass the value TRUE, since all such options are Booleans.</p>\n<p>A column of a foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">force_not_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level <code class=\"literal\">null</code> option). This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NOT_NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">force_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as <code class=\"literal\">NULL</code> even if the value is quoted. Without this option, only unquoted values matching the null string are returned as <code class=\"literal\">NULL</code>. This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NULL</code> option.</p>\n</dd>\n</dl>\n</div>\n<p><code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_QUOTE</code> option is currently not supported by <code class=\"literal\">file_fdw</code>.</p>\n<p>These options can only be specified for a foreign table or its columns, not in the options of the <code class=\"literal\">file_fdw</code> foreign-data wrapper, nor in the options of a server or user mapping using the wrapper.</p>\n<p>Changing table-level options requires being a superuser or having the privileges of the role <code class=\"literal\">pg_read_server_files</code> (to use a filename) or the role <code class=\"literal\">pg_execute_server_program</code> (to use a program), for security reasons: only certain users should be able to control which file is read or which program is run. In principle regular users could be allowed to change the other options, but that's not supported at present.</p>\n<p>When specifying the <code class=\"literal\">program</code> option, keep in mind that the option string is executed by the shell. If you need to pass any arguments to the command that come from an untrusted source, you must be careful to strip or escape any characters that might have special meaning to the shell. For security reasons, it is best to use a fixed command string, or at least avoid passing any user input in it.</p>\n<p>For a foreign table using <code class=\"literal\">file_fdw</code>, <code class=\"command\">EXPLAIN</code> shows the name of the file to be read or program to be run. For a file, unless <code class=\"literal\">COSTS OFF</code> is specified, the file size (in bytes) is shown as well.</p>\n<div class=\"example\" id=\"id-1.11.7.25.14\">\n<p class=\"title\"><strong>Example\u00a0F.1.\u00a0Create a Foreign Table for PostgreSQL CSV Logs</strong></p>\n<div class=\"example-contents\">\n<p>One of the obvious uses for <code class=\"literal\">file_fdw</code> is to make the PostgreSQL activity log available as a table for querying. To do this, first you must be <a class=\"link\" href=\"/docs/18/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-CSVLOG\" title=\"19.8.4.\u00a0Using CSV-Format Log Output\">logging to a CSV file,</a> which here we will call <code class=\"literal\">pglog.csv</code>. First, install <code class=\"literal\">file_fdw</code> as an extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION file_fdw;\n</pre>\n<p>Then create a foreign server:</p>\n<pre class=\"programlisting\">CREATE SERVER pglog FOREIGN DATA WRAPPER file_fdw;\n</pre>\n<p>Now you are ready to create the foreign data table. Using the <code class=\"command\">CREATE FOREIGN TABLE</code> command, you will need to define the columns for the table, the CSV file name, and its format:</p>\n<pre class=\"programlisting\">CREATE FOREIGN TABLE pglog (\n  log_time timestamp(3) with time zone,\n  user_name text,\n  database_name text,\n  process_id integer,\n  connection_from text,\n  session_id text,\n  session_line_num bigint,\n  command_tag text,\n  session_start_time timestamp with time zone,\n  virtual_transaction_id text,\n  transaction_id bigint,\n  error_severity text,\n  sql_state_code text,\n  message text,\n  detail text,\n  hint text,\n  internal_query text,\n  internal_query_pos integer,\n  context text,\n  query text,\n  query_pos integer,\n  location text,\n  application_name text,\n  backend_type text,\n  leader_pid integer,\n  query_id bigint\n) SERVER pglog\nOPTIONS ( filename 'log/pglog.csv', format 'csv' );\n</pre>\n<p>That's it \u2014 now you can query your log directly. In production, of course, you would need to define some way to deal with log rotation.</p>\n</div>\n</div><br class=\"example-break\">\n<div class=\"example\" id=\"id-1.11.7.25.15\">\n<p class=\"title\"><strong>Example\u00a0F.2.\u00a0Create a Foreign Table with an Option on a Column</strong></p>\n<div class=\"example-contents\">\n<p>To set the <code class=\"literal\">force_null</code> option for a column, use the <code class=\"literal\">OPTIONS</code> keyword.</p>\n<pre class=\"programlisting\">CREATE FOREIGN TABLE films (\n code char(5) NOT NULL,\n title text NOT NULL,\n rating text OPTIONS (force_null 'true')\n) SERVER film_server\nOPTIONS ( filename 'films/db.csv', format 'csv' );\n</pre>\n</div>\n</div><br class=\"example-break\">\n</div>", "manual_path": "/docs/18/file-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether the data has a header line, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "default", "definition": "Specifies the string that represents a default value, the same as COPY 's DEFAULT option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "on_error", "definition": "Specifies how to behave when encountering an error converting a column's input value into its data type, the same as COPY 's ON_ERROR option."}, {"name": "reject_limit", "definition": "Specifies the maximum number of errors tolerated while converting a column's input value to its data type, the same as COPY 's REJECT_LIMIT option."}, {"name": "log_verbosity", "definition": "Specifies the amount of messages emitted by file_fdw , the same as COPY 's LOG_VERBOSITY option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "3a50d8e658a12e9ec3405a8fd6dae6ec70a2fe3837297394492fb97a95b01306", "runtime_verified": false}, "19": {"facts": [{"label": "Interface family", "value": "Foreign-data wrapper"}, {"label": "Handler or routine", "value": "file_fdw_handler"}, {"label": "Recorded callbacks", "value": "10"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "fileIterateForeignScan"}, {"state": "No handler registered in this build", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "Not registered"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether to skip a header line, or how many header lines to skip, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "default", "definition": "Specifies the string that represents a default value, the same as COPY 's DEFAULT option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "on_error", "definition": "Specifies how to behave when encountering an error converting a column's input value into its data type, the same as COPY 's ON_ERROR option."}, {"name": "reject_limit", "definition": "Specifies the maximum number of errors tolerated while converting a column's input value to its data type, the same as COPY 's REJECT_LIMIT option."}, {"name": "log_verbosity", "definition": "Specifies the amount of messages emitted by file_fdw , the same as COPY 's LOG_VERBOSITY option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=19", "label": "Foreign-data wrapper catalog"}, {"url": "/e/file_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=19", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 19beta4 source archive", "label": "19beta4", "major": "19", "channel": "preview", "revision": "83157ee9c599d03b2f7a3d73ef3a56ec24e0e79cc2b3501a64d1364f56398c86", "source_url": "https://ftp.postgresql.org/pub/source/v19beta4/postgresql-19beta4.tar.bz2", "source_snapshot_utc": ""}, "sources": [{"url": "/docs/19/file-fdw.html", "path": "file-fdw.html", "label": "PostgreSQL 19 English manual", "sha256": "a292666e5a6ab0a2f62cf0ce333ab09c5b86be22919ba1edb8be06472245c5ee"}, {"url": "https://ftp.postgresql.org/pub/source/v19beta4/postgresql-19beta4.tar.bz2", "line": 183, "path": "contrib/file_fdw/file_fdw.c", "label": "contrib/file_fdw/file_fdw.c:183", "sha256": "00d45cce47466fb799f1285fb78113446eab16480e00c3fbfeae9a9a3439a1ca", "archive_sha256": "83157ee9c599d03b2f7a3d73ef3a56ec24e0e79cc2b3501a64d1364f56398c86"}], "sections": [{"title": "Interface and capability boundaries", "paragraphs": ["The matrix records callbacks actually registered in this source build. Registration identifies an implemented interface hook; options, query shape, privileges and provider rules determine whether an operation is allowed.", "The complete same-version manual below retains configuration, constraints and examples. No runtime capability test is claimed."]}, {"title": "File access boundary", "paragraphs": ["The file_fdw module provides the foreign-data wrapper file_fdw , which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by COPY FROM ; see COPY for details. Access to data files is currently read-only."]}, {"code": "{\n\tFdwRoutine *fdwroutine = makeNode(FdwRoutine);\n\n\tfdwroutine->GetForeignRelSize = fileGetForeignRelSize;\n\tfdwroutine->GetForeignPaths = fileGetForeignPaths;\n\tfdwroutine->GetForeignPlan = fileGetForeignPlan;\n\tfdwroutine->ExplainForeignScan = fileExplainForeignScan;\n\tfdwroutine->BeginForeignScan = fileBeginForeignScan;\n\tfdwroutine->IterateForeignScan = fileIterateForeignScan;\n\tfdwroutine->ReScanForeignScan = fileReScanForeignScan;\n\tfdwroutine->EndForeignScan = fileEndForeignScan;\n\tfdwroutine->AnalyzeForeignTable = fileAnalyzeForeignTable;\n\tfdwroutine->IsForeignScanParallelSafe = fileIsForeignScanParallelSafe;\n\n\tPG_RETURN_POINTER(fdwroutine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "description": ["Reads server-side files or program output through the foreign-data wrapper interface."], "manual_html": "<div class=\"sect1\" id=\"FILE-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.15.\u00a0file_fdw \u2014 access data files in the server's file system </h2>\n</div>\n</div>\n</div>\n<p>The <code class=\"filename\">file_fdw</code> module provides the foreign-data wrapper <code class=\"function\">file_fdw</code>, which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by <code class=\"command\">COPY FROM</code>; see <a class=\"xref\" href=\"/docs/19/sql-copy.html\" title=\"COPY\"><span class=\"refentrytitle\">COPY</span></a> for details. Access to data files is currently read-only.</p>\n<p>A foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">filename</code></span></dt>\n<dd>\n<p>Specifies the file to be read. Relative paths are relative to the data directory. Either <code class=\"literal\">filename</code> or <code class=\"literal\">program</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">program</code></span></dt>\n<dd>\n<p>Specifies the command to be executed. The standard output of this command will be read as though <code class=\"command\">COPY FROM PROGRAM</code> were used. Either <code class=\"literal\">program</code> or <code class=\"literal\">filename</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">format</code></span></dt>\n<dd>\n<p>Specifies the data format, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">FORMAT</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">header</code></span></dt>\n<dd>\n<p>Specifies whether to skip a header line, or how many header lines to skip, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">HEADER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">delimiter</code></span></dt>\n<dd>\n<p>Specifies the data delimiter character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">DELIMITER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">quote</code></span></dt>\n<dd>\n<p>Specifies the data quote character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">QUOTE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">escape</code></span></dt>\n<dd>\n<p>Specifies the data escape character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ESCAPE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">null</code></span></dt>\n<dd>\n<p>Specifies the data null string, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">default</code></span></dt>\n<dd>\n<p>Specifies the string that represents a default value, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">DEFAULT</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">encoding</code></span></dt>\n<dd>\n<p>Specifies the data encoding, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ENCODING</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">on_error</code></span></dt>\n<dd>\n<p>Specifies how to behave when encountering an error converting a column's input value into its data type, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ON_ERROR</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">reject_limit</code></span></dt>\n<dd>\n<p>Specifies the maximum number of errors tolerated while converting a column's input value to its data type, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">REJECT_LIMIT</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">log_verbosity</code></span></dt>\n<dd>\n<p>Specifies the amount of messages emitted by <code class=\"literal\">file_fdw</code>, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">LOG_VERBOSITY</code> option.</p>\n</dd>\n</dl>\n</div>\n<p>Note that while <code class=\"command\">COPY</code> allows options such as <code class=\"literal\">HEADER</code> to be specified without a corresponding value, the foreign table option syntax requires a value to be present in all cases. To activate <code class=\"command\">COPY</code> options typically written without a value, you can pass the value TRUE, since all such options accept Booleans.</p>\n<p>A column of a foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">force_not_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level <code class=\"literal\">null</code> option). This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NOT_NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">force_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as <code class=\"literal\">NULL</code> even if the value is quoted. Without this option, only unquoted values matching the null string are returned as <code class=\"literal\">NULL</code>. This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NULL</code> option.</p>\n</dd>\n</dl>\n</div>\n<p><code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_QUOTE</code> option is currently not supported by <code class=\"literal\">file_fdw</code>.</p>\n<p>These options can only be specified for a foreign table or its columns, not in the options of the <code class=\"literal\">file_fdw</code> foreign-data wrapper, nor in the options of a server or user mapping using the wrapper.</p>\n<p>Changing table-level options requires being a superuser or having the privileges of the role <code class=\"literal\">pg_read_server_files</code> (to use a filename) or the role <code class=\"literal\">pg_execute_server_program</code> (to use a program), for security reasons: only certain users should be able to control which file is read or which program is run. In principle regular users could be allowed to change the other options, but that's not supported at present.</p>\n<p>When specifying the <code class=\"literal\">program</code> option, keep in mind that the option string is executed by the shell. If you need to pass any arguments to the command that come from an untrusted source, you must be careful to strip or escape any characters that might have special meaning to the shell. For security reasons, it is best to use a fixed command string, or at least avoid passing any user input in it.</p>\n<p>For a foreign table using <code class=\"literal\">file_fdw</code>, <code class=\"command\">EXPLAIN</code> shows the name of the file to be read or program to be run. For a file, unless <code class=\"literal\">COSTS OFF</code> is specified, the file size (in bytes) is shown as well.</p>\n<div class=\"example\" id=\"id-1.11.7.25.14\">\n<p class=\"title\"><strong>Example\u00a0F.1.\u00a0Create a Foreign Table for PostgreSQL CSV Logs</strong></p>\n<div class=\"example-contents\">\n<p>One of the obvious uses for <code class=\"literal\">file_fdw</code> is to make the PostgreSQL activity log available as a table for querying. To do this, first you must be <a class=\"link\" href=\"/docs/19/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-CSVLOG\" title=\"19.8.4.\u00a0Using CSV-Format Log Output\">logging to a CSV file,</a> which here we will call <code class=\"literal\">pglog.csv</code>. First, install <code class=\"literal\">file_fdw</code> as an extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION file_fdw;\n</pre>\n<p>Then create a foreign server:</p>\n<pre class=\"programlisting\">CREATE SERVER pglog FOREIGN DATA WRAPPER file_fdw;\n</pre>\n<p>Now you are ready to create the foreign data table. Using the <code class=\"command\">CREATE FOREIGN TABLE</code> command, you will need to define the columns for the table, the CSV file name, and its format:</p>\n<pre class=\"programlisting\">CREATE FOREIGN TABLE pglog (\n  log_time timestamp(3) with time zone,\n  user_name text,\n  database_name text,\n  process_id integer,\n  connection_from text,\n  session_id text,\n  session_line_num bigint,\n  command_tag text,\n  session_start_time timestamp with time zone,\n  virtual_transaction_id text,\n  transaction_id bigint,\n  error_severity text,\n  sql_state_code text,\n  message text,\n  detail text,\n  hint text,\n  internal_query text,\n  internal_query_pos integer,\n  context text,\n  query text,\n  query_pos integer,\n  location text,\n  application_name text,\n  backend_type text,\n  leader_pid integer,\n  query_id bigint\n) SERVER pglog\nOPTIONS ( filename 'log/pglog.csv', format 'csv' );\n</pre>\n<p>That's it \u2014 now you can query your log directly. In production, of course, you would need to define some way to deal with log rotation.</p>\n</div>\n</div><br class=\"example-break\">\n<div class=\"example\" id=\"id-1.11.7.25.15\">\n<p class=\"title\"><strong>Example\u00a0F.2.\u00a0Create a Foreign Table with an Option on a Column</strong></p>\n<div class=\"example-contents\">\n<p>To set the <code class=\"literal\">force_null</code> option for a column, use the <code class=\"literal\">OPTIONS</code> keyword.</p>\n<pre class=\"programlisting\">CREATE FOREIGN TABLE films (\n code char(5) NOT NULL,\n title text NOT NULL,\n rating text OPTIONS (force_null 'true')\n) SERVER film_server\nOPTIONS ( filename 'films/db.csv', format 'csv' );\n</pre>\n</div>\n</div><br class=\"example-break\">\n</div>", "manual_path": "/docs/19/file-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether to skip a header line, or how many header lines to skip, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "default", "definition": "Specifies the string that represents a default value, the same as COPY 's DEFAULT option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "on_error", "definition": "Specifies how to behave when encountering an error converting a column's input value into its data type, the same as COPY 's ON_ERROR option."}, {"name": "reject_limit", "definition": "Specifies the maximum number of errors tolerated while converting a column's input value to its data type, the same as COPY 's REJECT_LIMIT option."}, {"name": "log_verbosity", "definition": "Specifies the amount of messages emitted by file_fdw , the same as COPY 's LOG_VERBOSITY option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "e872a000cbfc81be3c44b9a665e3ea7226545043214ef722efa0b01366fb56d4", "runtime_verified": false}, "20": {"facts": [{"label": "Interface family", "value": "Foreign-data wrapper"}, {"label": "Handler or routine", "value": "file_fdw_handler"}, {"label": "Recorded callbacks", "value": "10"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "fileIterateForeignScan"}, {"state": "No handler registered in this build", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "Not registered"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether to skip a header line, or how many header lines to skip, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "default", "definition": "Specifies the string that represents a default value, the same as COPY 's DEFAULT option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "on_error", "definition": "Specifies how to behave when encountering an error converting a column's input value into its data type, the same as COPY 's ON_ERROR option."}, {"name": "reject_limit", "definition": "Specifies the maximum number of errors tolerated while converting a column's input value to its data type, the same as COPY 's REJECT_LIMIT option."}, {"name": "log_verbosity", "definition": "Specifies the amount of messages emitted by file_fdw , the same as COPY 's LOG_VERBOSITY option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=20", "label": "Foreign-data wrapper catalog"}, {"url": "/e/file_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=20", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 20devel source archive", "label": "20devel", "major": "20", "channel": "devel", "revision": "4d3346909b201ac1648232cf290462a7070c119326f56196f1f0253ed80fae41", "source_url": "https://ftp.postgresql.org/pub/snapshot/dev/postgresql-snapshot.tar.bz2", "source_snapshot_utc": "26-Sep-2026 20:22"}, "sources": [{"url": "/docs/devel/file-fdw.html", "path": "file-fdw.html", "label": "PostgreSQL 20 English manual", "sha256": "14a0163b890979be72e7fce6b99b1803e73a3b259cc6ae2141d2f0b797acfd9d"}, {"url": "https://ftp.postgresql.org/pub/snapshot/dev/postgresql-snapshot.tar.bz2", "line": 183, "path": "contrib/file_fdw/file_fdw.c", "label": "contrib/file_fdw/file_fdw.c:183", "sha256": "6972e3c38c8fa7c716f948251c338d65901280c96d4f4fcf21f7ddbb71ec25fc", "archive_sha256": "4d3346909b201ac1648232cf290462a7070c119326f56196f1f0253ed80fae41"}], "sections": [{"title": "Interface and capability boundaries", "paragraphs": ["The matrix records callbacks actually registered in this source build. Registration identifies an implemented interface hook; options, query shape, privileges and provider rules determine whether an operation is allowed.", "The complete same-version manual below retains configuration, constraints and examples. No runtime capability test is claimed."]}, {"title": "File access boundary", "paragraphs": ["The file_fdw module provides the foreign-data wrapper file_fdw , which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by COPY FROM ; see COPY for details. Access to data files is currently read-only."]}, {"code": "{\n\tFdwRoutine *fdwroutine = makeNode(FdwRoutine);\n\n\tfdwroutine->GetForeignRelSize = fileGetForeignRelSize;\n\tfdwroutine->GetForeignPaths = fileGetForeignPaths;\n\tfdwroutine->GetForeignPlan = fileGetForeignPlan;\n\tfdwroutine->ExplainForeignScan = fileExplainForeignScan;\n\tfdwroutine->BeginForeignScan = fileBeginForeignScan;\n\tfdwroutine->IterateForeignScan = fileIterateForeignScan;\n\tfdwroutine->ReScanForeignScan = fileReScanForeignScan;\n\tfdwroutine->EndForeignScan = fileEndForeignScan;\n\tfdwroutine->AnalyzeForeignTable = fileAnalyzeForeignTable;\n\tfdwroutine->IsForeignScanParallelSafe = fileIsForeignScanParallelSafe;\n\n\tPG_RETURN_POINTER(fdwroutine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "description": ["Reads server-side files or program output through the foreign-data wrapper interface."], "manual_html": "<div class=\"sect1\" id=\"FILE-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.15.\u00a0file_fdw \u2014 access data files in the server's file system </h2>\n</div>\n</div>\n</div>\n<p>The <code class=\"filename\">file_fdw</code> module provides the foreign-data wrapper <code class=\"function\">file_fdw</code>, which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by <code class=\"command\">COPY FROM</code>; see <a class=\"xref\" href=\"/docs/devel/sql-copy.html\" title=\"COPY\"><span class=\"refentrytitle\">COPY</span></a> for details. Access to data files is currently read-only.</p>\n<p>A foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">filename</code></span></dt>\n<dd>\n<p>Specifies the file to be read. Relative paths are relative to the data directory. Either <code class=\"literal\">filename</code> or <code class=\"literal\">program</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">program</code></span></dt>\n<dd>\n<p>Specifies the command to be executed. The standard output of this command will be read as though <code class=\"command\">COPY FROM PROGRAM</code> were used. Either <code class=\"literal\">program</code> or <code class=\"literal\">filename</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">format</code></span></dt>\n<dd>\n<p>Specifies the data format, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">FORMAT</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">header</code></span></dt>\n<dd>\n<p>Specifies whether to skip a header line, or how many header lines to skip, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">HEADER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">delimiter</code></span></dt>\n<dd>\n<p>Specifies the data delimiter character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">DELIMITER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">quote</code></span></dt>\n<dd>\n<p>Specifies the data quote character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">QUOTE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">escape</code></span></dt>\n<dd>\n<p>Specifies the data escape character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ESCAPE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">null</code></span></dt>\n<dd>\n<p>Specifies the data null string, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">default</code></span></dt>\n<dd>\n<p>Specifies the string that represents a default value, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">DEFAULT</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">encoding</code></span></dt>\n<dd>\n<p>Specifies the data encoding, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ENCODING</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">on_error</code></span></dt>\n<dd>\n<p>Specifies how to behave when encountering an error converting a column's input value into its data type, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ON_ERROR</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">reject_limit</code></span></dt>\n<dd>\n<p>Specifies the maximum number of errors tolerated while converting a column's input value to its data type, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">REJECT_LIMIT</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">log_verbosity</code></span></dt>\n<dd>\n<p>Specifies the amount of messages emitted by <code class=\"literal\">file_fdw</code>, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">LOG_VERBOSITY</code> option.</p>\n</dd>\n</dl>\n</div>\n<p>Note that while <code class=\"command\">COPY</code> allows options such as <code class=\"literal\">HEADER</code> to be specified without a corresponding value, the foreign table option syntax requires a value to be present in all cases. To activate <code class=\"command\">COPY</code> options typically written without a value, you can pass the value TRUE, since all such options accept Booleans.</p>\n<p>A column of a foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">force_not_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level <code class=\"literal\">null</code> option). This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NOT_NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">force_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as <code class=\"literal\">NULL</code> even if the value is quoted. Without this option, only unquoted values matching the null string are returned as <code class=\"literal\">NULL</code>. This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NULL</code> option.</p>\n</dd>\n</dl>\n</div>\n<p><code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_QUOTE</code> option is currently not supported by <code class=\"literal\">file_fdw</code>.</p>\n<p>These options can only be specified for a foreign table or its columns, not in the options of the <code class=\"literal\">file_fdw</code> foreign-data wrapper, nor in the options of a server or user mapping using the wrapper.</p>\n<p>Changing table-level options requires being a superuser or having the privileges of the role <code class=\"literal\">pg_read_server_files</code> (to use a filename) or the role <code class=\"literal\">pg_execute_server_program</code> (to use a program), for security reasons: only certain users should be able to control which file is read or which program is run. In principle regular users could be allowed to change the other options, but that's not supported at present.</p>\n<p>When specifying the <code class=\"literal\">program</code> option, keep in mind that the option string is executed by the shell. If you need to pass any arguments to the command that come from an untrusted source, you must be careful to strip or escape any characters that might have special meaning to the shell. For security reasons, it is best to use a fixed command string, or at least avoid passing any user input in it.</p>\n<p>For a foreign table using <code class=\"literal\">file_fdw</code>, <code class=\"command\">EXPLAIN</code> shows the name of the file to be read or program to be run. For a file, unless <code class=\"literal\">COSTS OFF</code> is specified, the file size (in bytes) is shown as well.</p>\n<div class=\"example\" id=\"id-1.11.7.25.14\">\n<p class=\"title\"><strong>Example\u00a0F.1.\u00a0Create a Foreign Table for PostgreSQL CSV Logs</strong></p>\n<div class=\"example-contents\">\n<p>One of the obvious uses for <code class=\"literal\">file_fdw</code> is to make the PostgreSQL activity log available as a table for querying. To do this, first you must be <a class=\"link\" href=\"/docs/devel/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-CSVLOG\" title=\"19.8.4.\u00a0Using CSV-Format Log Output\">logging to a CSV file,</a> which here we will call <code class=\"literal\">pglog.csv</code>. First, install <code class=\"literal\">file_fdw</code> as an extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION file_fdw;\n</pre>\n<p>Then create a foreign server:</p>\n<pre class=\"programlisting\">CREATE SERVER pglog FOREIGN DATA WRAPPER file_fdw;\n</pre>\n<p>Now you are ready to create the foreign data table. Using the <code class=\"command\">CREATE FOREIGN TABLE</code> command, you will need to define the columns for the table, the CSV file name, and its format:</p>\n<pre class=\"programlisting\">CREATE FOREIGN TABLE pglog (\n  log_time timestamp(3) with time zone,\n  user_name text,\n  database_name text,\n  process_id integer,\n  connection_from text,\n  session_id text,\n  session_line_num bigint,\n  command_tag text,\n  session_start_time timestamp with time zone,\n  virtual_transaction_id text,\n  transaction_id bigint,\n  error_severity text,\n  sql_state_code text,\n  message text,\n  detail text,\n  hint text,\n  internal_query text,\n  internal_query_pos integer,\n  context text,\n  query text,\n  query_pos integer,\n  location text,\n  application_name text,\n  backend_type text,\n  leader_pid integer,\n  query_id bigint\n) SERVER pglog\nOPTIONS ( filename 'log/pglog.csv', format 'csv' );\n</pre>\n<p>That's it \u2014 now you can query your log directly. In production, of course, you would need to define some way to deal with log rotation.</p>\n</div>\n</div><br class=\"example-break\">\n<div class=\"example\" id=\"id-1.11.7.25.15\">\n<p class=\"title\"><strong>Example\u00a0F.2.\u00a0Create a Foreign Table with an Option on a Column</strong></p>\n<div class=\"example-contents\">\n<p>To set the <code class=\"literal\">force_null</code> option for a column, use the <code class=\"literal\">OPTIONS</code> keyword.</p>\n<pre class=\"programlisting\">CREATE FOREIGN TABLE films (\n code char(5) NOT NULL,\n title text NOT NULL,\n rating text OPTIONS (force_null 'true')\n) SERVER film_server\nOPTIONS ( filename 'films/db.csv', format 'csv' );\n</pre>\n</div>\n</div><br class=\"example-break\">\n</div>", "manual_path": "/docs/devel/file-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether to skip a header line, or how many header lines to skip, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "default", "definition": "Specifies the string that represents a default value, the same as COPY 's DEFAULT option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "on_error", "definition": "Specifies how to behave when encountering an error converting a column's input value into its data type, the same as COPY 's ON_ERROR option."}, {"name": "reject_limit", "definition": "Specifies the maximum number of errors tolerated while converting a column's input value to its data type, the same as COPY 's REJECT_LIMIT option."}, {"name": "log_verbosity", "definition": "Specifies the amount of messages emitted by file_fdw , the same as COPY 's LOG_VERBOSITY option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "e872a000cbfc81be3c44b9a665e3ea7226545043214ef722efa0b01366fb56d4", "runtime_verified": false}}}, "snapshot": {"facts": [{"label": "Interface family", "value": "Foreign-data wrapper"}, {"label": "Handler or routine", "value": "file_fdw_handler"}, {"label": "Recorded callbacks", "value": "10"}], "tables": [{"key": "callbacks", "rows": [{"state": "Handler registered; conditions apply", "feature": "Scan rows", "callback": "IterateForeignScan", "implementation": "fileIterateForeignScan"}, {"state": "No handler registered in this build", "feature": "INSERT", "callback": "ExecForeignInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "UPDATE", "callback": "ExecForeignUpdate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "DELETE", "callback": "ExecForeignDelete", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "TRUNCATE", "callback": "ExecForeignTruncate", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Join path pushdown", "callback": "GetForeignJoinPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Upper paths, including aggregation", "callback": "GetForeignUpperPaths", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Batch insert", "callback": "ExecForeignBatchInsert", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Asynchronous append execution", "callback": "ForeignAsyncRequest", "implementation": "Not registered"}, {"state": "No handler registered in this build", "feature": "Import schema", "callback": "ImportForeignSchema", "implementation": "Not registered"}], "title": "Registered interface handlers", "columns": [{"key": "feature", "label": "Interface operation"}, {"key": "state", "label": "Source observation"}, {"key": "callback", "label": "Callback"}, {"key": "implementation", "label": "Implementation"}]}, {"key": "options", "rows": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether the data has a header line, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "default", "definition": "Specifies the string that represents a default value, the same as COPY 's DEFAULT option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "on_error", "definition": "Specifies how to behave when encountering an error converting a column's input value into its data type, the same as COPY 's ON_ERROR option."}, {"name": "reject_limit", "definition": "Specifies the maximum number of errors tolerated while converting a column's input value to its data type, the same as COPY 's REJECT_LIMIT option."}, {"name": "log_verbosity", "definition": "Specifies the amount of messages emitted by file_fdw , the same as COPY 's LOG_VERBOSITY option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "title": "Documented options", "columns": [{"key": "name", "label": "Option"}, {"key": "definition", "label": "Same-version definition"}]}], "related": [{"url": "/wiki/catalog/pg_foreign_data_wrapper/?v=18", "label": "Foreign-data wrapper catalog"}, {"url": "/e/file_fdw/", "label": "Existing extension catalogue identity"}, {"url": "/wiki/plan/foreign-scan/?v=18", "label": "Foreign Scan plan node"}], "release": {"ref": "PostgreSQL 18.6 source archive", "label": "18.6", "major": "18", "channel": "stable", "revision": "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f", "source_url": "https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2", "source_snapshot_utc": ""}, "sources": [{"url": "/docs/18/file-fdw.html", "path": "file-fdw.html", "label": "PostgreSQL 18 English manual", "sha256": "5da35cee02e73ec6656a2020d8351046cad9283a137b45064bee58f1ff7eb787"}, {"url": "https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2", "line": 183, "path": "contrib/file_fdw/file_fdw.c", "label": "contrib/file_fdw/file_fdw.c:183", "sha256": "d79ec21c08be6a806b0710aab09698678ddb24103d3470702e66ee1523432125", "archive_sha256": "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"}], "sections": [{"title": "Interface and capability boundaries", "paragraphs": ["The matrix records callbacks actually registered in this source build. Registration identifies an implemented interface hook; options, query shape, privileges and provider rules determine whether an operation is allowed.", "The complete same-version manual below retains configuration, constraints and examples. No runtime capability test is claimed."]}, {"title": "File access boundary", "paragraphs": ["The file_fdw module provides the foreign-data wrapper file_fdw , which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by COPY FROM ; see COPY for details. Access to data files is currently read-only."]}, {"code": "{\n\tFdwRoutine *fdwroutine = makeNode(FdwRoutine);\n\n\tfdwroutine->GetForeignRelSize = fileGetForeignRelSize;\n\tfdwroutine->GetForeignPaths = fileGetForeignPaths;\n\tfdwroutine->GetForeignPlan = fileGetForeignPlan;\n\tfdwroutine->ExplainForeignScan = fileExplainForeignScan;\n\tfdwroutine->BeginForeignScan = fileBeginForeignScan;\n\tfdwroutine->IterateForeignScan = fileIterateForeignScan;\n\tfdwroutine->ReScanForeignScan = fileReScanForeignScan;\n\tfdwroutine->EndForeignScan = fileEndForeignScan;\n\tfdwroutine->AnalyzeForeignTable = fileAnalyzeForeignTable;\n\tfdwroutine->IsForeignScanParallelSafe = fileIsForeignScanParallelSafe;\n\n\tPG_RETURN_POINTER(fdwroutine);\n}", "title": "Registered implementation in core source"}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "description": ["Reads server-side files or program output through the foreign-data wrapper interface."], "manual_html": "<div class=\"sect1\" id=\"FILE-FDW\">\n<div class=\"titlepage\">\n<div>\n<div>\n<h2 class=\"title\">F.15.\u00a0file_fdw \u2014 access data files in the server's file system </h2>\n</div>\n</div>\n</div>\n<p>The <code class=\"filename\">file_fdw</code> module provides the foreign-data wrapper <code class=\"function\">file_fdw</code>, which can be used to access data files in the server's file system, or to execute programs on the server and read their output. The data file or program output must be in a format that can be read by <code class=\"command\">COPY FROM</code>; see <a class=\"xref\" href=\"/docs/18/sql-copy.html\" title=\"COPY\"><span class=\"refentrytitle\">COPY</span></a> for details. Access to data files is currently read-only.</p>\n<p>A foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">filename</code></span></dt>\n<dd>\n<p>Specifies the file to be read. Relative paths are relative to the data directory. Either <code class=\"literal\">filename</code> or <code class=\"literal\">program</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">program</code></span></dt>\n<dd>\n<p>Specifies the command to be executed. The standard output of this command will be read as though <code class=\"command\">COPY FROM PROGRAM</code> were used. Either <code class=\"literal\">program</code> or <code class=\"literal\">filename</code> must be specified, but not both.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">format</code></span></dt>\n<dd>\n<p>Specifies the data format, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">FORMAT</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">header</code></span></dt>\n<dd>\n<p>Specifies whether the data has a header line, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">HEADER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">delimiter</code></span></dt>\n<dd>\n<p>Specifies the data delimiter character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">DELIMITER</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">quote</code></span></dt>\n<dd>\n<p>Specifies the data quote character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">QUOTE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">escape</code></span></dt>\n<dd>\n<p>Specifies the data escape character, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ESCAPE</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">null</code></span></dt>\n<dd>\n<p>Specifies the data null string, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">default</code></span></dt>\n<dd>\n<p>Specifies the string that represents a default value, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">DEFAULT</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">encoding</code></span></dt>\n<dd>\n<p>Specifies the data encoding, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ENCODING</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">on_error</code></span></dt>\n<dd>\n<p>Specifies how to behave when encountering an error converting a column's input value into its data type, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">ON_ERROR</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">reject_limit</code></span></dt>\n<dd>\n<p>Specifies the maximum number of errors tolerated while converting a column's input value to its data type, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">REJECT_LIMIT</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">log_verbosity</code></span></dt>\n<dd>\n<p>Specifies the amount of messages emitted by <code class=\"literal\">file_fdw</code>, the same as <code class=\"command\">COPY</code>'s <code class=\"literal\">LOG_VERBOSITY</code> option.</p>\n</dd>\n</dl>\n</div>\n<p>Note that while <code class=\"command\">COPY</code> allows options such as <code class=\"literal\">HEADER</code> to be specified without a corresponding value, the foreign table option syntax requires a value to be present in all cases. To activate <code class=\"command\">COPY</code> options typically written without a value, you can pass the value TRUE, since all such options are Booleans.</p>\n<p>A column of a foreign table created using this wrapper can have the following options:</p>\n<div class=\"variablelist\">\n<dl class=\"variablelist\">\n<dt><span class=\"term\"><code class=\"literal\">force_not_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level <code class=\"literal\">null</code> option). This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NOT_NULL</code> option.</p>\n</dd>\n<dt><span class=\"term\"><code class=\"literal\">force_null</code></span></dt>\n<dd>\n<p>This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as <code class=\"literal\">NULL</code> even if the value is quoted. Without this option, only unquoted values matching the null string are returned as <code class=\"literal\">NULL</code>. This has the same effect as listing the column in <code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_NULL</code> option.</p>\n</dd>\n</dl>\n</div>\n<p><code class=\"command\">COPY</code>'s <code class=\"literal\">FORCE_QUOTE</code> option is currently not supported by <code class=\"literal\">file_fdw</code>.</p>\n<p>These options can only be specified for a foreign table or its columns, not in the options of the <code class=\"literal\">file_fdw</code> foreign-data wrapper, nor in the options of a server or user mapping using the wrapper.</p>\n<p>Changing table-level options requires being a superuser or having the privileges of the role <code class=\"literal\">pg_read_server_files</code> (to use a filename) or the role <code class=\"literal\">pg_execute_server_program</code> (to use a program), for security reasons: only certain users should be able to control which file is read or which program is run. In principle regular users could be allowed to change the other options, but that's not supported at present.</p>\n<p>When specifying the <code class=\"literal\">program</code> option, keep in mind that the option string is executed by the shell. If you need to pass any arguments to the command that come from an untrusted source, you must be careful to strip or escape any characters that might have special meaning to the shell. For security reasons, it is best to use a fixed command string, or at least avoid passing any user input in it.</p>\n<p>For a foreign table using <code class=\"literal\">file_fdw</code>, <code class=\"command\">EXPLAIN</code> shows the name of the file to be read or program to be run. For a file, unless <code class=\"literal\">COSTS OFF</code> is specified, the file size (in bytes) is shown as well.</p>\n<div class=\"example\" id=\"id-1.11.7.25.14\">\n<p class=\"title\"><strong>Example\u00a0F.1.\u00a0Create a Foreign Table for PostgreSQL CSV Logs</strong></p>\n<div class=\"example-contents\">\n<p>One of the obvious uses for <code class=\"literal\">file_fdw</code> is to make the PostgreSQL activity log available as a table for querying. To do this, first you must be <a class=\"link\" href=\"/docs/18/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-CSVLOG\" title=\"19.8.4.\u00a0Using CSV-Format Log Output\">logging to a CSV file,</a> which here we will call <code class=\"literal\">pglog.csv</code>. First, install <code class=\"literal\">file_fdw</code> as an extension:</p>\n<pre class=\"programlisting\">CREATE EXTENSION file_fdw;\n</pre>\n<p>Then create a foreign server:</p>\n<pre class=\"programlisting\">CREATE SERVER pglog FOREIGN DATA WRAPPER file_fdw;\n</pre>\n<p>Now you are ready to create the foreign data table. Using the <code class=\"command\">CREATE FOREIGN TABLE</code> command, you will need to define the columns for the table, the CSV file name, and its format:</p>\n<pre class=\"programlisting\">CREATE FOREIGN TABLE pglog (\n  log_time timestamp(3) with time zone,\n  user_name text,\n  database_name text,\n  process_id integer,\n  connection_from text,\n  session_id text,\n  session_line_num bigint,\n  command_tag text,\n  session_start_time timestamp with time zone,\n  virtual_transaction_id text,\n  transaction_id bigint,\n  error_severity text,\n  sql_state_code text,\n  message text,\n  detail text,\n  hint text,\n  internal_query text,\n  internal_query_pos integer,\n  context text,\n  query text,\n  query_pos integer,\n  location text,\n  application_name text,\n  backend_type text,\n  leader_pid integer,\n  query_id bigint\n) SERVER pglog\nOPTIONS ( filename 'log/pglog.csv', format 'csv' );\n</pre>\n<p>That's it \u2014 now you can query your log directly. In production, of course, you would need to define some way to deal with log rotation.</p>\n</div>\n</div><br class=\"example-break\">\n<div class=\"example\" id=\"id-1.11.7.25.15\">\n<p class=\"title\"><strong>Example\u00a0F.2.\u00a0Create a Foreign Table with an Option on a Column</strong></p>\n<div class=\"example-contents\">\n<p>To set the <code class=\"literal\">force_null</code> option for a column, use the <code class=\"literal\">OPTIONS</code> keyword.</p>\n<pre class=\"programlisting\">CREATE FOREIGN TABLE films (\n code char(5) NOT NULL,\n title text NOT NULL,\n rating text OPTIONS (force_null 'true')\n) SERVER film_server\nOPTIONS ( filename 'films/db.csv', format 'csv' );\n</pre>\n</div>\n</div><br class=\"example-break\">\n</div>", "manual_path": "/docs/18/file-fdw.html", "evidence_kind": "source and documentation", "comparison_data": {"options": [{"name": "filename", "definition": "Specifies the file to be read. Relative paths are relative to the data directory. Either filename or program must be specified, but not both."}, {"name": "program", "definition": "Specifies the command to be executed. The standard output of this command will be read as though COPY FROM PROGRAM were used. Either program or filename must be specified, but not both."}, {"name": "format", "definition": "Specifies the data format, the same as COPY 's FORMAT option."}, {"name": "header", "definition": "Specifies whether the data has a header line, the same as COPY 's HEADER option."}, {"name": "delimiter", "definition": "Specifies the data delimiter character, the same as COPY 's DELIMITER option."}, {"name": "quote", "definition": "Specifies the data quote character, the same as COPY 's QUOTE option."}, {"name": "escape", "definition": "Specifies the data escape character, the same as COPY 's ESCAPE option."}, {"name": "null", "definition": "Specifies the data null string, the same as COPY 's NULL option."}, {"name": "default", "definition": "Specifies the string that represents a default value, the same as COPY 's DEFAULT option."}, {"name": "encoding", "definition": "Specifies the data encoding, the same as COPY 's ENCODING option."}, {"name": "on_error", "definition": "Specifies how to behave when encountering an error converting a column's input value into its data type, the same as COPY 's ON_ERROR option."}, {"name": "reject_limit", "definition": "Specifies the maximum number of errors tolerated while converting a column's input value to its data type, the same as COPY 's REJECT_LIMIT option."}, {"name": "log_verbosity", "definition": "Specifies the amount of messages emitted by file_fdw , the same as COPY 's LOG_VERBOSITY option."}, {"name": "force_not_null", "definition": "This is a Boolean option. If true, it specifies that values of the column should not be matched against the null string (that is, the table-level null option). This has the same effect as listing the column in COPY 's FORCE_NOT_NULL option."}, {"name": "force_null", "definition": "This is a Boolean option. If true, it specifies that values of the column which match the null string are returned as NULL even if the value is quoted. Without this option, only unquoted values matching the null string are returned as NULL . This has the same effect as listing the column in COPY 's FORCE_NULL option."}], "callbacks": {"EndForeignScan": "fileEndForeignScan", "GetForeignPlan": "fileGetForeignPlan", "GetForeignPaths": "fileGetForeignPaths", "BeginForeignScan": "fileBeginForeignScan", "GetForeignRelSize": "fileGetForeignRelSize", "ReScanForeignScan": "fileReScanForeignScan", "ExplainForeignScan": "fileExplainForeignScan", "IterateForeignScan": "fileIterateForeignScan", "AnalyzeForeignTable": "fileAnalyzeForeignTable", "IsForeignScanParallelSafe": "fileIsForeignScanParallelSafe"}, "source_options": [], "protocol_versions": {}}, "comparison_hash": "3a50d8e658a12e9ec3405a8fd6dae6ec70a2fe3837297394492fb97a95b01306", "runtime_verified": false}, "comparison": {"left": "15", "right": "16", "status": "changed", "diff": "--- PostgreSQL 15\n+++ PostgreSQL 16\n@@ -45,6 +45,10 @@\n       \"name\": \"null\"\n     },\n     {\n+      \"definition\": \"Specifies the string that represents a default value, the same as COPY 's DEFAULT option.\",\n+      \"name\": \"default\"\n+    },\n+    {\n       \"definition\": \"Specifies the data encoding, the same as COPY 's ENCODING option.\",\n       \"name\": \"encoding\"\n     },"}}