swuecho
12/3/2016 - 7:23 AM

Postgres: CSV file as a table using FDW

Postgres: CSV file as a table using FDW

-- Installs "file_fdw" extension and creates foreign table to work with data from CSV file.
-- See also the comment below which helps to automate the process for Google Spreadsheets
-- Another option would be using Multicorn for Google Spreadsheets, but it requires additional steps  
-- (see https://wiki.postgresql.org/wiki/Foreign_data_wrappers).

CREATE EXTENSION file_fdw;
CREATE SERVER import FOREIGN DATA WRAPPER file_fdw;
CREATE FOREIGN TABLE table1_import (
  col1 text,
  col2 text,
  ...
) SERVER import OPTIONS ( filename '/path/to/file.csv', format 'csv' );

--