Enable executing multiple statements while execution via sqlalchemy

后端 未结 3 1259
难免孤独
难免孤独 2020-12-17 16:41

I have a DDL object (create_function_foo) that contains a create function statement. In first line of it I put DROP FUNCTION IF EXISTS foo; but

3条回答
  •  情话喂你
    2020-12-17 16:56

    Yeah... This seems like a bummer to me. I don't want to use the ORM so the accepted answer didn't work for me.

    I did this instead:

    with open('sql_statements_file.sql') as sql_file:
        for statement in sql_file.read().split(';'):
            if len(statement.strip()) > 0:
                 connection.execute(statement + ';')
    

    And then this failed for a CREATE function.... YMMV.

提交回复
热议问题