Last active
September 29, 2024 13:50
-
-
Save NikolayS/a819f139c37e0d54ad4a4ca70764f225 to your computer and use it in GitHub Desktop.
Postgres: CSV file as a table using FDW
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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" ( | |
col1 text, | |
col2 text, | |
... | |
) server "import" options ( | |
filename '/path/to/file.csv', | |
format 'csv', | |
header 'on' | |
); | |
-- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The full procedure for a public Google Spreadsheet (list of Pokemons as an example):
wget -O pokemons.csv\ "https://docs.google.com/spreadsheets/d/14mIpk_ceBWVnjc1cPAD7AWeXkE8-t729pcLqwcX_Iik/export?format=csv"
\r
:sed -n '2,$p' pokemons.csv