- Mastering PostGIS
- Dominik Mikiewicz Michal Mackiewicz Tomasz Nycz
- 282字
- 2021-07-02 22:52:20
Importing data non-interactively
For the non-interactive psql data import example we'll do a bit more than in the interactive mode. We'll:
- Import the full earthquakes dataset
- Select a subset of earthquakes data mentioned in the previous example and insert it into its own table
- Import another dataset - in this case the Ordnance Survey's POIs
Basically the non-interactive usage of psql means we simply provide it with an SQL to execute. This way we can put together many statements without having to execute them one by one.
Once again we will need the data model prior to loading the data, and then a \COPY command will be used.
If you're still in psql, you can execute a script by simply typing:
\i path\to\the\script.sql
For example:
\i F:/mastering_postgis/chapter02/code/data_import_earthquakes.sql
You should see a similar output:
mastering_postgis-# \i F:/mastering_postgis/chapter02/code/data_import_earthquakes.sql
CREATE SCHEMA
psql:F:/mastering_postgis/chapter02/code/data_import_earthquakes.sql:5: NOTICE: table "earthquakes_csv" does not exist, skipping
DROP TABLE
CREATE TABLE
COPY 25
psql:F:/mastering_postgis/chapter02/code/data_import_earthquakes.sql:58: NOTICE: table "earthquakes_csv_subset" does not exist, skipping
DROP TABLE
SELECT 25
mastering_postgis-#
If you quit psql already, type the following command into cmd:
psql -h host -p port -U user -d database -f path\to\the\script.sql
For example:
psql -h localhost -p 5434 -U postgres -d mastering_postgis -f F:\mastering_postgis\chapter02\code\data_import_earthquakes.sql
You should see a similar output:
F:\mastering_postgis\chapter02>psql -h localhost -p 5434 -U postgres -d mastering_postgis -f F:\mastering_postgis\chapter02\code\data_import_earthquakes.sql
psql:F:/mastering_postgis/chapter02/code/data_import_earthquakes.sql:2: NOTICE: schema "data_import" already exists, skipping
CREATE SCHEMA
DROP TABLE
CREATE TABLE
COPY 25
DROP TABLE
SELECT 25
The script executed earlier is in the book's code repository under Chapter02/code/ data_import_earthquakes.sql.
Loading OS POI data is now a piece of cake. This dataset is in a bit of a different format though, so it requires slight adjustments. You can review the code in Chapter02/code/ data_import_gb_poi.sql.
- 繪制進(jìn)程圖:可視化D++語言(第1冊)
- ABB工業(yè)機(jī)器人編程全集
- 我的J2EE成功之路
- 基于LabWindows/CVI的虛擬儀器設(shè)計(jì)與應(yīng)用
- Data Wrangling with Python
- Spark大數(shù)據(jù)技術(shù)與應(yīng)用
- 自動控制理論(非自動化專業(yè))
- 網(wǎng)絡(luò)安全技術(shù)及應(yīng)用
- 新編計(jì)算機(jī)圖形學(xué)
- 水晶石影視動畫精粹:After Effects & Nuke 影視后期合成
- 大數(shù)據(jù)案例精析
- Learning Cassandra for Administrators
- Data Analysis with R(Second Edition)
- 人工智能云平臺:原理、設(shè)計(jì)與應(yīng)用
- 網(wǎng)站規(guī)劃與網(wǎng)頁設(shè)計(jì)