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

Parameterized queries with tuples don't work #3090

Open
matthias-Q opened this issue Feb 6, 2025 · 1 comment
Open

Parameterized queries with tuples don't work #3090

matthias-Q opened this issue Feb 6, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@matthias-Q
Copy link

Describe the bug

I was trying to use parameters in a query like:

select * from table_name where id_ in (:ids)

using wr.athena.start_query_execution I provided a list of strings
params={"ids":tuple(["1","1000"])}

This fails with the following error message:
IN value and list items must be the same type or coercible to a common type. Cannot find common type between varchar and array(varchar(4)), all types (without duplicates): [varchar, array(varchar(4))]
There seems to be some conversion going on with the second parameter.

Then I tried to use the paramstyle 'qmark'. The query looked like this:

select * from table_name where id_ in (?,?)

and the query failed with this message
IN value and list items must be the same type or coercible to a common type. Cannot find common type between varchar and integer, all types (without duplicates): [varchar, integer]. Both elements of that list are strings!. For some reason it seems to get converted to integer.

How to Reproduce

*P.S. Please do not attach files as it's considered a security risk. Add code snippets directly in the message body as much as possible.*

Expected behavior

Tuple/Lists into a parameter should not be converted.

Your project

No response

Screenshots

No response

OS

Linux

Python version

3.11

AWS SDK for pandas version

awswrangler>=3.11

Additional context

No response

@matthias-Q matthias-Q added the bug Something isn't working label Feb 6, 2025
@Rutuja2506
Copy link

Rutuja2506 commented Feb 24, 2025

Hi @matthias-Q, You are using a tuple (("1", "1000")) for the IN clause, but Athena expects the list values to have a consistent type. When you provide a tuple of strings, Athena interprets it as an array of varchar, which causes the type mismatch.

To resolve this, ensure that all values in the list or tuple are of the same type, either as strings or as integers, depending on your table's column data type.

params = {"ids": ["1", "1000"]} # Make sure all values are strings
If the id_ column is of integer type, you can try passing the integers instead:

params = {"ids": [1, 1000]} # Use integers if the column is of type integer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants