forked from asyncee/fias2pgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import_addrobj.sh
30 lines (24 loc) · 926 Bytes
/
import_addrobj.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 ADDROBJ FILES'
if [ -f ./_data/ADDROB01.DBF ]; then
mv ./_data/ADDROB01.DBF ./_data/ADDROBJ.DBF
echo '++++++++++++++++++ ADDROBJ INITIAL FILE MOVED'
fi
pgdbf ./_data/ADDROBJ.DBF | iconv -f cp866 -t utf-8 | PGOPTIONS=--search_path=$SCHEMA psql $DB $OPTIONS
echo '++++++++++++++++++ INITIAL ADDROBJ TABLE CREATED'
for FULLPATH in `find ./_data/ADDROB* -type f`
do
FILE="${FULLPATH##*/}"
TABLE="${FILE%.*}"
if [ $TABLE = 'ADDROBJ' ]; then
echo 'SKIPPING ADDROBJ'
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 ADDROBJ"
PGOPTIONS=--search_path=$SCHEMA psql -d $DB -c "INSERT INTO addrobj SELECT * FROM $TABLE; DROP TABLE $TABLE;" $OPTIONS
fi
done