Skip to content

Instantly share code, notes, and snippets.

@swuecho
Forked from NikolayS/file_fdw__csv.sql
Created December 3, 2016 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swuecho/fbebd122af13a15505948482768eda56 to your computer and use it in GitHub Desktop.
Save swuecho/fbebd122af13a15505948482768eda56 to your computer and use it in GitHub Desktop.
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' );
--
@swuecho
Copy link
Author

swuecho commented Dec 3, 2016

use sqlachemy auto generate schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment