Revision 1922
Added by Aaron Marcuse-Kubitza over 12 years ago
inputs/input.Makefile | ||
---|---|---|
149 | 149 |
echo 'DROP SCHEMA IF EXISTS "$(datasrc)" CASCADE;'|$(psqlAsBien) |
150 | 150 |
|
151 | 151 |
import/install-%: _always |
152 |
env datasrc=$(datasrc) table=$* $(withCatSrcs) $(bin)/csv2ddl$(if\
|
|
152 |
env schema=$(datasrc) table=$* $(withCatSrcs) $(bin)/csv2ddl$(if\
|
|
153 | 153 |
$(debug),|tee /dev/fd/2)|$(psqlAsBien) |
154 | 154 |
#-echo "COPY $(datasrc).;"|$(psqlAsBien) |
155 | 155 |
|
bin/csv2ddl | ||
---|---|---|
22 | 22 |
+' <header >ddl') |
23 | 23 |
|
24 | 24 |
# Get config from env vars |
25 |
datasrc = opts.get_env_var('datasrc', None, env_names)
|
|
25 |
schema = opts.get_env_var('schema', None, env_names)
|
|
26 | 26 |
table = opts.get_env_var('table', None, env_names) |
27 |
if datasrc == None or table == None: usage_err()
|
|
27 |
if schema == None or table == None: usage_err()
|
|
28 | 28 |
|
29 | 29 |
# Get col names |
30 | 30 |
reader, col_names = csvs.reader_and_header(sys.stdin) |
31 | 31 |
|
32 | 32 |
# Write CREATE TABLE statement |
33 | 33 |
out = sys.stdout |
34 |
out.write('CREATE TABLE '+esc_name(datasrc)+'.'+esc_name(table)+' (\n')
|
|
34 |
out.write('CREATE TABLE '+esc_name(schema)+'.'+esc_name(table)+' (\n')
|
|
35 | 35 |
out.write('row_num serial NOT NULL\n') |
36 | 36 |
for col_name in col_names: out.write(', '+esc_name(col_name)+' text\n') |
37 | 37 |
out.write(');\n') |
Also available in: Unified diff
csv2ddl: Renamed schema name env var from datasrc to schema to reflect what it is, and to make the script general beyond importing inputs