User Tools

Site Tools


postgres:copy_command

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
postgres:copy_command [2013/07/25 22:03]
mh
postgres:copy_command [2014/09/10 21:22] (current)
Line 1: Line 1:
 +[[europa.csv]]
  
  
 +<​code>​
 world=# create table membership_raw world=# create table membership_raw
 (State text, GNI text, wage text, UN text, CoE text, OSCE text, EU text, EEA text, CU text, Schengen text, euro text, OECD text, WTO text, ESA text, NATO text, ICC text, VWP text); (State text, GNI text, wage text, UN text, CoE text, OSCE text, EU text, EEA text, CU text, Schengen text, euro text, OECD text, WTO text, ESA text, NATO text, ICC text, VWP text);
- 
-[[europa.csv]] 
  
 world=# \encoding latin1 world=# \encoding latin1
  
 world=# copy membership_raw from '/​home/​mh/​world/​europa.csv'​ delimiter ';';​ world=# copy membership_raw from '/​home/​mh/​world/​europa.csv'​ delimiter ';';​
 +
 +world=# select count(code2) from countries where name in (select state from membership_raw);​
 + count
 +-----
 +
 +world=# create table countries_x_organisations (code character(3),​ organisation_id integer);  ​
 +
 +world=# insert into organisations (id, name) values (nextval('​world_seq'​),​ '​Euro'​);  ​
 +world=# insert into organisations (id, name) values (nextval('​world_seq'​),​ '​EU'​);  ​
 +
 +world=# insert into countries_x_organisations (code, organisation_id)
 +world-# select code, (select id from organisations where name = '​EU'​) from countries where name in (select state from membership_raw where eu = '​EU'​);​
 +
 +
 +world=# select c.name, o.name from countries c join countries_x_organisations cxo
 +        on cxo.code = c.code join organisations o on o.id = cxo.organisation_id;​
 +
 +</​code>​
  
  
postgres/copy_command.1374782593.txt.gz ยท Last modified: 2014/09/10 21:22 (external edit)