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

Filter with a list of tuple #550

Closed
Andarius opened this issue Apr 2, 2020 · 3 comments
Closed

Filter with a list of tuple #550

Andarius opened this issue Apr 2, 2020 · 3 comments

Comments

@Andarius
Copy link

@Andarius Andarius commented Apr 2, 2020

  • asyncpg version: 0.20.1
  • PostgreSQL version: 12-alpine
  • Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
    the issue with a local PostgreSQL install?
    : no
  • Python version: 3.8
  • Platform: Kde
  • Do you use pgbouncer?: no
  • Did you install asyncpg with pip?: no
  • If you built asyncpg locally, which version of Cython did you use?: -
  • Can the issue be reproduced under both asyncio and
    uvloop?
    :

I'm trying to fetch records based on a list of tuple but I keep getting:
asyncpg.exceptions._base.InternalClientError: could not resolve query result and/or argument types in 6 attempt

Here is the request:

SELECT id from my_table where (label, user_id)::record = any($1::record[]) (where $1 is a list of tuple)

@elprans
Copy link
Member

@elprans elprans commented Apr 2, 2020

Postgres does not support input of anonymous tuple types. That said, asyncpg should handle this better.

@Andarius
Copy link
Author

@Andarius Andarius commented Apr 3, 2020

So, what would be the equivalent of SELECT * FROM my_table WHERE (label, user_id) IN (('T', 1), ('R', 2), ('T', 3)) ?

@Andarius Andarius changed the title Searching given a list of tuple Filter with a list of tuple Apr 3, 2020
@elprans
Copy link
Member

@elprans elprans commented Apr 23, 2020

If you can afford it, create an explicit composite type:

CREATE TYPE label_id_pair AS (label text, id int)

and then

SELECT id from my_table where (label, user_id)::record = any($1::label_id_pair[])
@Andarius Andarius closed this Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.