Revision 2487
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
860 | 860 |
if not create: raise |
861 | 861 |
return put(db, table, row, pkey, row_ct_ref) # insert new row |
862 | 862 |
|
863 |
def put_table(db, out_table, in_tables, mapping, row_ct_ref=None): |
|
863 |
def put_table(db, out_table, in_tables, mapping, row_ct_ref=None, |
|
864 |
temp_prefix=None): |
|
864 | 865 |
'''Recovers from errors. |
865 | 866 |
Only works under PostgreSQL (uses INSERT RETURNING). |
866 | 867 |
@param in_tables The main input table to select from, followed by a list of |
... | ... | |
868 | 869 |
@param mapping dict(out_table_col=in_table_col, ...) |
869 | 870 |
* out_table_col: sql_gen.Col|str |
870 | 871 |
* in_table_col: sql_gen.Col Wrap literal values in a sql_gen.NamedCol |
872 |
@param temp_prefix The prefix of generated temp tables. |
|
873 |
Defaults to out_table.name. |
|
871 | 874 |
@return sql_gen.Col Where the output pkeys are made available |
872 | 875 |
''' |
873 | 876 |
out_table = sql_gen.as_Table(out_table) |
874 | 877 |
for in_table_col in mapping.itervalues(): |
875 | 878 |
assert isinstance(in_table_col, sql_gen.Col) |
879 |
if temp_prefix == None: temp_prefix = out_table.name |
|
876 | 880 |
|
877 | 881 |
def log_debug(msg): db.log_debug(msg, level=1.5) |
878 | 882 |
|
... | ... | |
880 | 884 |
log_debug('Inserting these input columns into ' |
881 | 885 |
+strings.as_tt(out_table.to_str(db))+':\n'+strings.as_table(mapping)) |
882 | 886 |
|
883 |
temp_prefix = out_table.name |
|
884 | 887 |
pkeys = sql_gen.Table(temp_prefix+'_pkeys') |
885 | 888 |
|
886 | 889 |
# Create input joins from list of input tables |
Also available in: Unified diff
sql.py: put_table(): Added optional param temp_prefix for the prefix of generated temp tables