forked from asyncee/fias2pgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import_house.sh
30 lines (24 loc) · 914 Bytes
/
import_house.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
DB=$1
SCHEMA=$2
OPTIONS=$3
echo '++++++++++++++++++ CHECKING HOUSES FILES'
if [ -f ./_data/HOUSE01.DBF ]; then
mv ./_data/HOUSE01.DBF ./_data/HOUSES.DBF
echo '++++++++++++++++++ HOUSES INITIAL FILE MOVED'
fi
pgdbf ./_data/HOUSES.DBF | iconv -f cp866 -t utf-8 | PGOPTIONS=--search_path=$SCHEMA psql $DB $OPTIONS
echo '++++++++++++++++++ INITIAL HOUSES TABLE CREATED'
for FULLPATH in `find ./_data/HOUSE* -type f`
do
FILE="${FULLPATH##*/}"
TABLE="${FILE%.*}"
if [ $TABLE = 'HOUSES' ]; then
echo 'SKIPPING HOUSES'
else
pgdbf $FULLPATH | iconv -f cp866 -t utf-8 | PGOPTIONS=--search_path=$SCHEMA psql $DB $OPTIONS
echo "++++++++++++++++++ TABLE $TABLE CREATED"
echo "++++++++++++++++++ INSERT $TABLE DATA INTO HOUSES"
PGOPTIONS=--search_path=$SCHEMA psql -d $DB -c "INSERT INTO houses SELECT * FROM $TABLE; DROP TABLE $TABLE;" $OPTIONS
fi
done