Revision 4257
Added by Aaron Marcuse-Kubitza about 12 years ago
bin/csv2db | ||
---|---|---|
33 | 33 |
# Get config from env vars |
34 | 34 |
table = opts.get_env_var('table', None, env_names) |
35 | 35 |
schema = opts.get_env_var('schema', 'public', env_names) |
36 |
has_row_num = opts.env_flag('has_row_num', True, env_names) |
|
36 | 37 |
db_config = opts.get_env_vars(sql.db_config_names, None, env_names) |
37 | 38 |
errors_table_only = opts.env_flag('errors_table_only', False, env_names) |
38 | 39 |
verbosity = util.cast(float, opts.get_env_var('verbosity', 3, env_names)) |
... | ... | |
82 | 83 |
# Select schema and escape names |
83 | 84 |
def esc_name(name): return db.esc_name(name) |
84 | 85 |
|
85 |
typed_cols = [sql_gen.TypedCol('row_num', 'serial', nullable=False)]+[ |
|
86 |
sql_gen.TypedCol(v, 'text') for v in col_names] |
|
86 |
typed_cols = [sql_gen.TypedCol(v, 'text') for v in col_names] |
|
87 |
if has_row_num: |
|
88 |
typed_cols.insert(0, sql_gen.TypedCol('row_num', 'serial', |
|
89 |
nullable=False)) |
|
87 | 90 |
|
88 | 91 |
log('Creating table') |
89 |
sql.create_table(db, table, typed_cols, col_indexes=False) |
|
92 |
sql.create_table(db, table, typed_cols, has_pkey=has_row_num, |
|
93 |
col_indexes=False) |
|
90 | 94 |
|
91 | 95 |
# Remove rows from any failed COPY FROM |
92 | 96 |
sql.truncate(db, table) |
Also available in: Unified diff
csv2db: Added has_row_num param to disable creating a row_num column