Skip to content
Get Started for Free

SQL API

The Snowflake SQL API allows you to submit SQL statements for execution over HTTP. LocalStack for Snowflake supports the SQL API, enabling you to execute single or multiple SQL statements locally.

The Snowflake emulator supports submitting multiple SQL statements in a single request. Separate each statement with a semicolon (;) and specify the statement count using one of the following methods:

Set MULTI_STATEMENT_COUNT in the session parameters. This setting is persistent for the entire session. When set to 0, the emulator accepts any number of statements without requiring an exact count. If set to a non-zero value, you must specify exactly that many statements in each batch.

conn = snowflake.connector.connect(
user="test",
password="test",
account="test",
host="snowflake.localhost.localstack.cloud",
session_parameters={"MULTI_STATEMENT_COUNT": 0}
)
with conn.cursor() as cur:
cur.execute("SELECT 1; SELECT 2; SELECT 3")
print(list(cur)) # First result
cur.nextset()
print(list(cur)) # Second result

Specify num_statements per query using the Python connector’s execute() method.

with conn.cursor() as cur:
cur.execute("SELECT 1; SELECT 2; SELECT 3", num_statements=3)
print(list(cur)) # First result
cur.nextset()
print(list(cur)) # Second result

If MULTI_STATEMENT_COUNT does not match the actual number of statements, an error is returned:

Actual statement count <actual_count> did not match the desired statement count <desired_count>.