Revision 2080
Added by Aaron Marcuse-Kubitza over 12 years ago
sql.py | ||
---|---|---|
373 | 373 |
|
374 | 374 |
if embeddable: |
375 | 375 |
# Create function |
376 |
function = 'pg_temp.'+('_'.join(map(clean_name,
|
|
377 |
['insert_returning', table] + cols)))
|
|
376 |
function = '_'.join(map(clean_name, ['insert', table] + cols))
|
|
377 |
qual_function = 'pg_temp.'+function
|
|
378 | 378 |
return_type = 'SETOF '+table+'.'+returning+'%TYPE' |
379 | 379 |
function_query = '''\ |
380 |
CREATE OR REPLACE FUNCTION '''+function+'''() RETURNS '''+return_type+''' |
|
380 |
CREATE OR REPLACE FUNCTION '''+qual_function+'''() RETURNS '''+return_type+'''
|
|
381 | 381 |
LANGUAGE sql |
382 | 382 |
AS $$'''+mogrify(db, query, params)+''';$$; |
383 | 383 |
''' |
384 | 384 |
run_query(db, function_query, cacheable=True) |
385 | 385 |
|
386 | 386 |
# Return query that uses function |
387 |
return mk_select(db, function+'()', table_is_esc=True) |
|
387 |
return mk_select(db, qual_function+'() AS '+function+' ('+returning+')', |
|
388 |
table_is_esc=True) # function alias is required in AS clause |
|
388 | 389 |
|
389 | 390 |
return (query, params) |
390 | 391 |
|
Also available in: Unified diff
sql.py: mk_insert_select(): embeddable: Make the column returned by the function have the same name as the returning column