Open Tim-Kracht opened 1 month ago
Hello @Tim-Kracht ,
Thanks for raising the issue, we are looking into it, will update.
Regards, Sujan
Hello @Tim-Kracht ,
The semicolon (;) is typically used to terminate SQL statements in interactive environments like SnowSQL, Snowflake Worksheets, or UI-based tools, where multiple queries can be executed in sequence.
However, when executing SQL queries programmatically (such as through the Snowpark API, Python connectors, or other programmatic interfaces), the semicolon is not required and can lead to errors if included. Programmatic interfaces treat each query separately, so the semicolon is unnecessary and can cause syntax errors.
To fix the issue: You can remove the semi-colon or clean_query = query.rstrip(';')
queries = (
"select query_start_time from snowflake.account_usage.access_history limit 1",
"select query_start_time from snowflake.account_usage.access_history limit 1;"
)
for query in queries:
print()
df = None
result = None
count = None
# Remove trailing semicolon if it exists
clean_query = query.rstrip(';')
print(f"{clean_query=}")
df = session.sql(clean_query)
try:
result = df.collect()
print(f"{result=}")
except Exception as ex:
print(f"{ex=}")
try:
count = df.count()
print(f"{count=}")
except Exception as ex:
print(f"{ex=}")
Regards, Sujan
Please answer these questions before submitting your issue. Thanks!
Python 3.11.10 (main, Sep 7 2024, 01:03:31) [Clang 15.0.0 (clang-1500.3.9.4)]
macOS-14.6.1-arm64-arm-64bit
pip freeze
)?asn1crypto==1.5.1 certifi==2024.8.30 cffi==1.17.1 charset-normalizer==3.3.2 cloudpickle==2.2.1 cryptography==43.0.1 filelock==3.16.0 idna==3.8 packaging==24.1 platformdirs==4.3.2 pycparser==2.22 PyJWT==2.9.0 pyOpenSSL==24.2.1 python-dotenv==1.0.1 pytz==2024.2 PyYAML==6.0.2 requests==2.32.3 snowflake-connector-python==3.12.1 snowflake-snowpark-python==1.21.1 sortedcontainers==2.4.0 tomlkit==0.13.2 typing_extensions==4.12.2 urllib3==2.2.2
Called
Session.sql()
for a query that ends with a;
then calledDataFrame.collect()
andDataFrame.count()
I expected to see the same behavior from a SQL compilation perspective.
DataFrame.collect()
worked as expected,DataFrame.count()
raised aSQL compilation error
The same query without the semicolon runs fine in both cases.