Project

General

Profile

« Previous | Next » 

Revision 2083

sql.py: mk_insert_select(): embeddable: Name the function alias "f" since it will just be wrapped in a nested SELECT, so the exact name doesn't matter (and won't be visible outside the nested SELECT anyway)

View differences:

lib/sql.py
373 373
    
374 374
    if embeddable:
375 375
        # Create function
376
        function = '_'.join(map(clean_name, ['insert', table] + cols))
377
        qual_function = 'pg_temp.'+function
376
        function = 'pg_temp.'+('_'.join(map(clean_name,
377
            ['insert', table] + cols)))
378 378
        return_type = 'SETOF '+table+'.'+returning+'%TYPE'
379 379
        function_query = '''\
380
CREATE OR REPLACE FUNCTION '''+qual_function+'''() RETURNS '''+return_type+'''
380
CREATE OR REPLACE FUNCTION '''+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, qual_function+'() AS '+function+' ('+returning+')',
387
        return mk_select(db, function+'() AS f ('+returning+')',
388 388
            table_is_esc=True) # function alias is required in AS clause
389 389
    
390 390
    return (query, params)

Also available in: Unified diff