);
BEGIN TRANSACTION;
DELETE FROM continent;
-COPY continent FROM PROGRAM 'curl -s http://download.geonames.org/export/dump/readme.txt | awk "/^Continent codes/ {ok=1} ok==1 && /^$/{exit} ok==1 {print \$0}" | tail -n +2 | sed -e "s/ : /\t/" -e "s/[\t ]\+geonameId=/\t/"' WITH (format 'text', NULL '');
+COPY continent FROM PROGRAM 'curl -s http://download.geonames.org/export/dump/readme.txt \
+| awk "/^Continent codes/ {ok=1} ok==1 && /^$/{exit} ok==1 {print \$0}" \
+| tail -n +2 \
+| sed -e "s/ : /\t/" -e "s/[\t ]\+geonameId=/\t/" \
+' WITH (format 'text', NULL '');
COMMIT;
altnames varchar(10000),
latitude numeric(7,4),
longitude numeric(7,4),
- feature_class char(1),
- feature_code varchar(10),
+-- NB 06.01.18 feature_class char(1),
+-- NB 06.01.18 feature_code varchar(10),
+ feature varchar(10),
country char(2),
cc2 varchar(200),
-- NB 06.01.18 admin1 varchar(20),
BEGIN TRANSACTION;
DELETE FROM geo;
-- NB 06.01.18 COPY geo FROM PROGRAM 'curl -s http://download.geonames.org/export/dump/allCountries.zip | zcat' WITH (format 'text', NULL '');
-COPY geo FROM PROGRAM 'curl -s http://download.geonames.org/export/dump/allCountries.zip | zcat | cut -f -10,15-' WITH (format 'text', NULL '');
+-- NB 06.01.18 COPY geo FROM PROGRAM 'curl -s http://download.geonames.org/export/dump/allCountries.zip | zcat | cut -f -10,15-' WITH (format 'text', NULL '');
+COPY geo FROM PROGRAM 'curl -s http://download.geonames.org/export/dump/allCountries.zip \
+| zcat \
+| awk "{\$7=\$7\".\"\$8;print}" FS="\t" OFS="\t" \
+| cut -f -7,9-10,15-
+' WITH (format 'text', NULL '');
COMMIT;
-- CREATE INDEX IF NOT EXISTS geofeature_country_idx ON geofeature (country);
BEGIN TRANSACTION;
DELETE FROM geofeature;
-COPY geofeature FROM PROGRAM 'curl -s http://www.geonames.org/export/codes.html | tr -d "\n" | sed "s/<.tr>/\n/g" | grep "<a name=.*<td" | sed -E -e "s/(<.?t[^>]*> *)/\t/g" -e "s/^.*?=.([A-Z0-9\.]*)[^\t]+\t/\1/" -e "s/\t+/\t/g" | cut -f 1-3 | grep -v "not available"' WITH (format 'text', NULL '');
+COPY geofeature FROM PROGRAM 'curl -s http://www.geonames.org/export/codes.html \
+| tr -d "\n" \
+| sed "s/<.tr>/\n/g" \
+| grep "<a name=.*<td" \
+| sed -E -e "s/(<.?t[^>]*> *)/\t/g" -e "s/^.*?=.([A-Z0-9\.]*)[^\t]+\t/\1/" -e "s/\t+/\t/g" \
+| cut -f 1-3 \
+| grep -v "not available"
+' WITH (format 'text', NULL '');
COMMIT;