Revision 2508
Added by Aaron Marcuse-Kubitza over 12 years ago
sql.py | ||
---|---|---|
861 | 861 |
if not create: raise |
862 | 862 |
return put(db, table, row, pkey, row_ct_ref) # insert new row |
863 | 863 |
|
864 |
def put_table(db, out_table, in_tables, mapping, row_ct_ref=None, into=None): |
|
864 |
def put_table(db, out_table, in_tables, mapping, row_ct_ref=None, into=None, |
|
865 |
default=None): |
|
865 | 866 |
'''Recovers from errors. |
866 | 867 |
Only works under PostgreSQL (uses INSERT RETURNING). |
867 | 868 |
@param in_tables The main input table to select from, followed by a list of |
... | ... | |
871 | 872 |
* in_table_col: sql_gen.Col Wrap literal values in a sql_gen.NamedCol |
872 | 873 |
@param into The table to contain the output and input pkeys. |
873 | 874 |
Defaults to `out_table.name+'-pkeys'`. |
875 |
@param default The value or input column to use as the pkey for missing rows |
|
874 | 876 |
@return sql_gen.Col Where the output pkeys are made available |
875 | 877 |
''' |
876 | 878 |
out_table = sql_gen.as_Table(out_table) |
... | ... | |
1026 | 1028 |
db.log_debug('Adding pkey on pkeys table to enable fast joins', level=2.5) |
1027 | 1029 |
index_pkey(db, into) |
1028 | 1030 |
|
1029 |
log_debug('Setting pkeys of missing rows to NULL')
|
|
1031 |
log_debug('Setting pkeys of missing rows to '+strings.as_tt(repr(default)))
|
|
1030 | 1032 |
missing_rows_joins = input_joins+[sql_gen.Join(into, |
1031 | 1033 |
{in_pkey: sql_gen.join_same_not_null}, sql_gen.filter_out)] |
1032 | 1034 |
# must use join_same_not_null or query will take forever |
1033 | 1035 |
insert_into_pkeys(missing_rows_joins, |
1034 |
[in_pkey_col, sql_gen.NamedCol(out_pkey, None)])
|
|
1036 |
[in_pkey_col, sql_gen.NamedCol(out_pkey, default)])
|
|
1035 | 1037 |
|
1036 | 1038 |
assert table_row_count(db, into) == table_row_count(db, in_table) |
1037 | 1039 |
|
Also available in: Unified diff
sql.py: put_table(): Added default param for the value or input column to use as the pkey for missing rows