From: Nicolas Boisselier Date: Fri, 5 Jan 2018 02:08:08 +0000 (+0000) Subject: lib/postgres/zipcode.sql X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=cbfeeb1de0cac82e78eacaa3c8c4038e1e3070d9;p=nb.git lib/postgres/zipcode.sql --- diff --git a/lib/postgres/zipcode b/lib/postgres/zipcode index dcf671fb..2982f4ee 100755 --- a/lib/postgres/zipcode +++ b/lib/postgres/zipcode @@ -1,6 +1,7 @@ #!/usr/bin/env perl use strict; use warnings; +die('obsolete !!!'); @ARGV = ('curl -s http://download.geonames.org/export/zip/allCountries.zip | zcat |'); #exec($ARGV[0]); exit; @@ -10,9 +11,9 @@ while (<>) { @_ = split("\t",$_); push @_,0 if (@_<12); - $_ = $_[0]; - $_[0] = $_[1]; - $_[1] = $_; + #$_ = $_[0]; + #$_[0] = $_[1]; + #$_[1] = $_; print join ("\t",@_)."\n"; diff --git a/lib/postgres/zipcode.sql b/lib/postgres/zipcode.sql index 103a7cee..0cdf7617 100644 --- a/lib/postgres/zipcode.sql +++ b/lib/postgres/zipcode.sql @@ -1,7 +1,7 @@ DROP TABLE IF EXISTS zipcode; CREATE TABLE IF NOT EXISTS zipcode ( - id varchar(20), country varchar(2), + code varchar(20), name varchar(180), state varchar(100), state_code varchar(20), @@ -12,16 +12,19 @@ CREATE TABLE IF NOT EXISTS zipcode ( latitude numeric(7,4), longitude numeric(7,4), accuracy smallint - -- PRIMARY KEY(id,country) ); -GRANT ALL ON ALL TABLES IN SCHEMA public TO www; -GRANT ALL ON ALL TABLES IN SCHEMA public TO nico; -GRANT ALL ON ALL TABLES IN SCHEMA public TO root; -CREATE INDEX IF NOT EXISTS zipcode_id_idx ON zipcode (id); -CREATE INDEX IF NOT EXISTS zipcode_country_countryx ON zipcode (country); -CREATE INDEX IF NOT EXISTS zipcode_name_namex ON zipcode (name); --- \copy zipcode from stdin with delimiter E'\t' null as ''; + +CREATE INDEX IF NOT EXISTS zipcode_code_idx ON zipcode (code); +CREATE INDEX IF NOT EXISTS zipcode_country_idx ON zipcode (country); +CREATE INDEX IF NOT EXISTS zipcode_name_idx ON zipcode (name); + +GRANT ALL ON TABLE zipcode TO www; +GRANT ALL ON TABLE zipcode TO nico; +GRANT ALL ON TABLE zipcode TO root; + BEGIN TRANSACTION; DELETE FROM zipcode; -COPY zipcode FROM stdin WITH (format 'text'); +-- COPY zipcode FROM stdin WITH (format 'text'); +COPY zipcode FROM PROGRAM 'curl -s http://download.geonames.org/export/zip/allCountries.zip | zcat | sed "s,\\\\,\\\\\\\\,g"' WITH (format 'text', NULL ''); +-- COPY geo FROM PROGRAM '/opt/nb/lib/postgres/zipcode' WITH (format 'text', NULL ''); COMMIT;