Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect number of parameters because of unused CTEs #20

Open
bdeboe opened this issue Dec 19, 2024 · 0 comments
Open

Incorrect number of parameters because of unused CTEs #20

bdeboe opened this issue Dec 19, 2024 · 0 comments

Comments

@bdeboe
Copy link
Contributor

bdeboe commented Dec 19, 2024

I'm running into trouble trying to craft an easy-to-read and reusable query using CTEs (in fact for this hybrid search demo). As long as all CTEs that have parameters are used, things work OK, but when I leave out a CTE that includes a parameter and still supply it, I get "Incorrect number of parameters", and when I leave it out I get a weird "Unable to allocate a license" error.

I'm not sure whether this sits at the SQLAlchemy-iris level or one level underneath, but I'm sure you can help me figure that out :-)

To reproduce:

from sqlalchemy import create_engine, text

username = 'demo'
password = 'demo'
hostname = 'localhost'
port = '1972' 
namespace = 'USER'
CONNECTION_STRING = f"iris://{username}:{password}@{hostname}:{port}/{namespace}"

engine = create_engine(CONNECTION_STRING)
connection = engine.connect()

sql = text("""
    WITH cte AS (
        SELECT 123 as n, :param as message
    ), 
    cte2 AS (
        SELECT *, :param2 as message2
        FROM cte
    )
    SELECT * FROM cte
""")

result = connection.execute(sql, { "param": "hello", "param2": "hello2" }).fetchall()
print(result)

you can easily play around selecting from cte or cte2, and include/exclude parameters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant