Revision 2072
Added by Aaron Marcuse-Kubitza over 12 years ago
sql.py | ||
---|---|---|
385 | 385 |
return (query, params) |
386 | 386 |
|
387 | 387 |
def insert_select(db, *args, **kw_args): |
388 |
'''For params, see mk_insert_select() and run_query()''' |
|
388 |
'''For params, see mk_insert_select() and run_query() |
|
389 |
@param into Name of temp table to place RETURNING values in |
|
390 |
''' |
|
391 |
into = kw_args.pop('into', None) |
|
392 |
if into != None: kw_args['embeddable'] = True |
|
389 | 393 |
recover = kw_args.pop('recover', None) |
390 | 394 |
cacheable = kw_args.pop('cacheable', True) |
391 | 395 |
|
392 | 396 |
query, params = mk_insert_select(db, *args, **kw_args) |
393 |
return run_query(db, query, params, recover, cacheable) |
|
397 |
if into == None: # return RETURNING values |
|
398 |
return run_query(db, query, params, recover, cacheable) |
|
399 |
else: # place RETURNING values in temp table |
|
400 |
run_query(db, 'DROP TABLE IF EXISTS '+into+' CASCADE') |
|
401 |
return run_query(db, 'CREATE TEMP TABLE '+into+' AS '+query, params) |
|
402 |
# CREATE TABLE returns SELECT tag with rowcount = # inserts |
|
394 | 403 |
|
395 | 404 |
default = object() # tells insert() to use the default value for a column |
396 | 405 |
|
Also available in: Unified diff
sql.py: insert_select(): Support placing RETURNING values in temp table