Revision 2960
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
1270 | 1270 |
pkeys_cols = [in_pkey_col, out_pkey_col] |
1271 | 1271 |
|
1272 | 1272 |
pkeys_table_exists_ref = [False] |
1273 |
def insert_into_pkeys(joins, cols): |
|
1274 |
query = mk_select(db, joins, cols, order_by=None, start=0) |
|
1273 |
def insert_into_pkeys(joins, cols, distinct=False): |
|
1274 |
kw_args = {} |
|
1275 |
if distinct: kw_args.update(dict(distinct_on=[in_pkey_col])) |
|
1276 |
query = mk_select(db, joins, cols, order_by=None, start=0, **kw_args) |
|
1277 |
|
|
1275 | 1278 |
if pkeys_table_exists_ref[0]: |
1276 | 1279 |
insert_select(db, into, pkeys_names, query) |
1277 | 1280 |
else: |
... | ... | |
1410 | 1413 |
elif has_joins: |
1411 | 1414 |
select_joins = input_joins+[sql_gen.Join(out_table, join_cols)] |
1412 | 1415 |
log_debug('Getting output table pkeys of existing/inserted rows') |
1413 |
insert_into_pkeys(select_joins, pkeys_cols) |
|
1416 |
insert_into_pkeys(select_joins, pkeys_cols, distinct=True)
|
|
1414 | 1417 |
else: |
1415 | 1418 |
add_row_num(db, insert_out_pkeys) # for joining with input pkeys |
1416 | 1419 |
|
Also available in: Unified diff
sql.py: put_table(): Getting output table pkeys of existing/inserted rows: Do a DISTINCT ON the input pkey (row_num) in case the plain JOIN matched multiple output table rows for one input table row