Revision 2189
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
528 | 528 |
|
529 | 529 |
if embeddable: |
530 | 530 |
# Create function |
531 |
function = 'pg_temp.'+('_'.join(map(clean_name, |
|
532 |
['insert', table] + cols))) |
|
531 |
function_name = '_'.join(map(clean_name, ['insert', table] + cols)) |
|
533 | 532 |
return_type = 'SETOF '+table+'.'+returning+'%TYPE' |
534 |
function_query = '''\ |
|
535 |
CREATE OR REPLACE FUNCTION '''+function+'''() RETURNS '''+return_type+''' |
|
533 |
while True: |
|
534 |
try: |
|
535 |
function = 'pg_temp.'+function_name |
|
536 |
function_query = '''\ |
|
537 |
CREATE FUNCTION '''+function+'''() RETURNS '''+return_type+''' |
|
536 | 538 |
LANGUAGE sql |
537 | 539 |
AS $$'''+mogrify(db, query, params)+''';$$; |
538 | 540 |
''' |
539 |
run_query(db, function_query) |
|
540 |
# don't cache because function def could change and then change back |
|
541 |
run_query(db, function_query, recover=True, cacheable=True) |
|
542 |
break # this version was successful |
|
543 |
except DuplicateFunctionException, e: |
|
544 |
function_name = next_version(function_name) |
|
545 |
# try again with next version of name |
|
541 | 546 |
|
542 | 547 |
# Return query that uses function |
543 | 548 |
return mk_select(db, function+'() AS f ('+returning+')', start=0, |
Also available in: Unified diff
sql.py: mk_insert_select(): embeddable: Fixed bug where the function may do different things when run, because the function (and other statements whose cached strings depend on the function name) may be run after the function definition would have changed, by versioning the function name and using CREATE FUNCTION instead of CREATE OR REPLACE FUNCTION so that its definition never changes