Home | 简体中文 | 繁体中文 | 杂文 | Search | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 作品与服务 | Email

5.2. copy

5.2.1. wget

http://www.postgresonline.com/journal/archives/325-Using-wget-directly-from-PostgreSQL-using-COPY-FROM-PROGRAM.html

			
CREATE TABLE worldbank_json(data json);
COPY worldbank_json 
  FROM PROGRAM 'C:/wget/wget.exe -q -O - "$@" "http://api.worldbank.org/countries?format=json&per_page=100&page=1"';
COPY worldbank_json 
  FROM PROGRAM 'C:/wget/wget.exe -q -O - "$@" "http://api.worldbank.org/countries?format=json&per_page=100&page=2"';
COPY worldbank_json 
 FROM PROGRAM 'C:/wget/wget.exe -q -O - "$@" "http://api.worldbank.org/countries?format=json&per_page=100&page=3"';
 
 WITH je AS (SELECT json_array_elements(data->1) AS jd 
FROM  worldbank_json)
SELECT jd->>'id' AS id, jd->>'name' As country, 
  jd#>>'{adminregion,id}' As region_id
FROM je ;
			
			
comments powered by Disqus