Open alexgrand opened 8 months ago
Looks like SQLAlchemy runs sqlalchemy.engine.default.DefaultDialect.do_execute
method which doesn't pass num_statements
parameter to the snowflake.connector.cursor.SnowflakeCursor.execute
and num_statements
is always set to None
Fixed by rewriting sqlalchemy cursor command via sqlalchemy do_execute
event:
from sqlalchemy import event
@event.listens_for(<engine>, 'do_execute')
def do_execute(cursor, statement, parameters, context):
return cursor.execute(statement, parameters, num_statements=0)
Any better option to fix it? Maybe I miss something?
Hello @alexgrand ,
Thank you for bringing up this matter. Currently, the MULTI_STATEMENT_COUNT parameter isn't supported for Snowflake SQLAlchemy. However, there are plans to tentatively support it in Q2 2024.
Regards, Sujan
Has there been any movement on adding this feature? In my understanding, Snowflake performs query planning optimization when presented with multiple SQL statements at once - this optimization would be lost if queries are submitted one at a time. I believe that makes this feature essential.
Fixed by rewriting sqlalchemy cursor command via sqlalchemy
do_execute
event:from sqlalchemy import event @event.listens_for(<engine>, 'do_execute') def do_execute(cursor, statement, parameters, context): return cursor.execute(statement, parameters, num_statements=0)
Any better option to fix it? Maybe I miss something?
This works for me also, but did you find any way of doing performance logging on each of the individual queries in the multi-query file?
Please answer these questions before submitting your issue. Thanks!
What version of Python are you using?
Python 3.10.12 (main, Jul 21 2023, 13:21:20) [GCC 11.3.0]
What operating system and processor architecture are you using?
Linux-5.19.0-50-generic-x86_64-with-glibc2.35
What are the component versions in the environment (
pip freeze
)?Snowflake connector, sqlalchemy:
What did you do?
What did you expect to see?
I expect to be able to run several statements in one SQL statement from file. Snowflake SQLAlchemy works same as python snowflake connector ^version 2.9.0