Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Sqlalchemy in statement is incorrectly compiled for the in clause

Open
#445 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python, sqlalchemy
Domain
databases

Research direction

Reproduce the issue using the shown create_engine, select, statement compilation, and conn.execute entry points on version 2.9.6. Compare the literal_binds output with the parameterized SQL and parameters sent during execution. Done means an IN clause containing True executes successfully without a boolean-versus-integer type mismatch.

Written by the indexing model from the issue text.

Description

Version 2.9.6

Repro:

from sqlalchemy import create_engine, MetaData, Table, select, column

# Assuming you have a working database connection string
engine = create_engine('...'). # make sure to specify the catalog

metadata = MetaData()
engine.execute("create table if not exists bogdankyryliuk.bool_test as select 1 as one_val, True as bool_val")
test_table = Table('bool_test', metadata, autoload_with=engine, schema='bogdankyryliuk')
stmt = select(test_table).where(test_table.c.bool_val.in_([True]))

compiled_stmt = stmt.compile(compile_kwargs={"literal_binds": True})
print(compiled_stmt)

with engine.connect() as conn:
    result = conn.execute(stmt)
    for row in result:
        print(row)

Compiled statement is printed as expected:

SELECT bogdankyryliuk.bool_test.one_val, bogdankyryliuk.bool_test.bool_val
FROM bogdankyryliuk.bool_test
WHERE bogdankyryliuk.bool_test.bool_val IN (true)

However conn.execute(stmt) executes different statement:

DatabaseError: (databricks.sql.exc.ServerOperationError) [DATATYPE_MISMATCH.DATA_DIFF_TYPES] Cannot resolve "(bool_val IN (1))" due to data type mismatch: Input to `in` should all be the same type, but it's ["BOOLEAN", "INT"]. SQLSTATE: 42K09; line 3 pos 40
[SQL: SELECT bogdankyryliuk.bool_test.one_val, bogdankyryliuk.bool_test.bool_val
FROM bogdankyryliuk.bool_test
WHERE bogdankyryliuk.bool_test.bool_val IN (%(bool_val_1_1)s)]
[parameters: {'bool_val_1_1': 1}]
(Background on this error at: https://sqlalche.me/e/14/4xp6)

That leads to the exception

Dominant language
Python
Stars
233
Forks
152
Avg merge
21h 5m
Merged PRs (30d)
10

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from databricks/databricks-sql-python

All issues in databricks/databricks-sql-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.