Skip to content

Commit 098ca00

Browse files
committed
Use temporary name to import external data and then rename
This way the table is never missing or empty while importing.
1 parent cf21015 commit 098ca00

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

themes/external/download-and-import.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@ import() {
6161
local file="$3"
6262
local inlayer="$4"
6363

64-
ogr2ogr -f PostgreSQL "PG:dbname=$db" -overwrite -nln "$layer" \
64+
ogr2ogr -f PostgreSQL "PG:dbname=$db" -overwrite -nln "${layer}_new" \
6565
-lco GEOMETRY_NAME=geom \
6666
-lco FID=id \
6767
-sql 'select "_ogr_geometry_" from '"$inlayer" \
6868
"/vsizip/$file.zip/$file"
6969

70-
psql --quiet -d "$DB" -c "ANALYZE $layer;"
70+
psql --quiet -d "$DB" -c "ANALYZE ${layer}_new;"
71+
psql --quiet -d "$DB" -c "BEGIN; DROP TABLE IF EXISTS $layer; ALTER TABLE ${layer}_new RENAME TO $layer; COMMIT;"
7172
}
7273

7374
import_dataset() {

0 commit comments

Comments
 (0)