Project

General

Profile

1
#!/bin/bash
2
# Usage: (must be run from a table subdir)
3
if false; then
4
#!/bin/bash
5
cd "$(dirname "$0")"
6
. path/to/import.sh
7

    
8
map_table
9
psql <<'EOF'
10
postprocess_commands...
11
EOF
12
fi
13

    
14
import_sh_dir="$(dirname "${BASH_SOURCE[0]}")"
15
root_dir="$import_sh_dir"/..
16
bin_dir="$root_dir"/bin
17

    
18
: "${schema="$(cd ..; basename "$PWD")"}"
19
: "${table="$(basename "$PWD")"}"
20
export schema table
21

    
22
psql ()
23
{
24
	(cat <<EOF
25
\set schema "$schema"
26
\set table "$table"
27
\set table_str '''"$table"'''
28
SET search_path TO "$schema", util;
29
EOF
30
	cat)|
31
	env no_search_path=1 "$bin_dir"/psql_verbose_vegbien
32
}
33

    
34
map_table ()
35
{
36
	make --directory=.. --makefile=../input.Makefile "$table"/map.csv
37
	(psql <<EOF
38
SELECT util.reset_map_table('pg_temp.map');
39
\copy pg_temp.map FROM 'map.csv' CSV HEADER;
40
SELECT util.set_col_names('"$table"', 'pg_temp.map'::regclass);
41
EOF
42
	)
43
}
(20-20/48)