$ psql -U postgres -d demo psql (9.3.1) demo=# CREATE TABLE "earthquake_table" ( demo(# id bigserial primary key, demo(# time timestamp, demo(# latitude float, demo(# longitude float, demo(# depth float, demo(# mag float, demo(# place varchar(255) demo(# ); CREATE TABLE
地理空間情報は後で追加する
demo=# SHOW DATESTYLE; DateStyle ----------- ISO, YMD (1 行)CSV と形式があっていない場合には
demo=# SET DATESTYLE = "ISO,YMD";
demo=# COPY "earthquake_table" (time,latitude,longitude,depth,mag,place) FROM '/tmp/query.csv' DELIMITERS ',' CSV HEADER; COPY 7816
demo=# select * from earthquake_table; id | time | latitude | longitude | depth | mag | place ------+------------------------+----------+--------------+---------+-----+---------------------------------------------- 1 | 2014-06-19 10:17:58.53 | -13.5767 | 166.8264 | 59.87 | 6.4 | 85km WNW of Sola, Vanuatu 2 | 2014-06-19 09:38:37.23 | -19.9607 | -70.9399 | 19.34 | 5.7 | 88km WNW of Iquique, Chile 3 | 2014-06-19 00:51:17.58 | -2.7551 | 102.3528 | 169.36 | 5.1 | 81km NNW of Curup, Indonesia 4 | 2014-06-18 02:47:09.34 | 24.2784 | 125.1907 | 23.1 | 5.2 | 58km S of Hirara, Japan 5 | 2014-06-17 19:56:21.26 | 1.5162 | 125.4812 | 79.86 | 5.3 | 34km ENE of Bitung, Indonesia 6 | 2014-06-17 16:04:42.51 | 1.1742 | 97.0354 | 32.73 | 5 | 161km SSE of Sinabang, Indonesia 7 | 2014-06-16 17:42:23.93 | 33.9862 | 139.5775 | 136.84 | 5.3 | 95km SE of Shimoda, Japan 8 | 2014-06-16 14:24:32.17 | 70.3499 | -15.4474 | 13.69 | 5 | 244km E of Ittoqqortoormiit, Greenland 9 | 2014-06-16 13:26:46.13 | 11.6893 | -81.3198 | 18.51 | 5.5 | 107km SSE of San Andres, Colombia 10 | 2014-06-16 12:01:08 | 67.6973 | -162.6119 | 24.2 | 5.7 | 31km ENE of Noatak, Alaska
demo=# SELECT AddGeometryColumn('public', 'earthquake_table', 'geom', 4326, 'POINT', 2 ); addgeometrycolumn ----------------------------------------------------------- public.earthquake_table.geom SRID:4326 TYPE:POINT DIMS:2 (1 行)
demo=# CREATE INDEX "cearthquake_table_geom_gist" ON "earthquake_table" USING GIST ("geom"); CREATE INDEX
demo=# UPDATE earthquake_table SET geom = ST_GeomFromText('POINT(' || longitude || ' ' || latitude || ')',4326); UPDATE 7816
demo=# select id, time, longitude, latitude, st_astext(geom) from earthquake_table; id | time | longitude | latitude | st_astext ------+------------------------+--------------+----------+----------------------------- 1 | 2014-06-19 10:17:58.53 | 166.8264 | -13.5767 | POINT(166.8264 -13.5767) 2 | 2014-06-19 09:38:37.23 | -70.9399 | -19.9607 | POINT(-70.9399 -19.9607) 3 | 2014-06-19 00:51:17.58 | 102.3528 | -2.7551 | POINT(102.3528 -2.7551) 4 | 2014-06-18 02:47:09.34 | 125.1907 | 24.2784 | POINT(125.1907 24.2784) 5 | 2014-06-17 19:56:21.26 | 125.4812 | 1.5162 | POINT(125.4812 1.5162) 6 | 2014-06-17 16:04:42.51 | 97.0354 | 1.1742 | POINT(97.0354 1.1742) 7 | 2014-06-16 17:42:23.93 | 139.5775 | 33.9862 | POINT(139.5775 33.9862) 8 | 2014-06-16 14:24:32.17 | -15.4474 | 70.3499 | POINT(-15.4474 70.3499) 9 | 2014-06-16 13:26:46.13 | -81.3198 | 11.6893 | POINT(-81.3198 11.6893) 10 | 2014-06-16 12:01:08 | -162.6119 | 67.6973 | POINT(-162.6119 67.6973)