Skip to content

Instantly share code, notes, and snippets.

@danbjoseph
Last active August 29, 2015 14:16
Show Gist options
  • Save danbjoseph/7dbf3f716302ad7e576a to your computer and use it in GitHub Desktop.
Save danbjoseph/7dbf3f716302ad7e576a to your computer and use it in GitHub Desktop.
copying data from csv to a new postgres table
  • file must be on same computer as postgres database
  • file must be UTF-8, though might be a way to define this as something else in the psql command
CREATE TABLE enumeration(
	"id" SERIAL PRIMARY KEY,
	"enumerator" TEXT, 
	"hh_id" TEXT, 
	"respondent_last" TEXT, 
	"respondent_first" TEXT, 
	... 	
)

COPY enumeration("enumerator", "hh_id", "respondent_last", "respondent_first", ...) FROM '/path/to/file.csv' DELIMITER ',' CSV;

ALTER TABLE enumeration ADD COLUMN geom geometry(POINT,4326);
UPDATE enumeration SET geom = ST_SetSRID(ST_MakePoint(cast(gps_longitude as float),cast(gps_latitude as float)),4326);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment