-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Array Query Parameter with IN operator #623
Comments
I'd need to see the code you're running to give you an exact answer but in general there is no way to do an inlist clause on a single parameter. You have to build the inlist clause manually. There are plenty of sql building libraries to do this for you, but it would end up looking like this:
Otherwise you can do an
Notice the double array because you're passing an entire array as a single parameter. The syntax isn't 100% above as I'm doing this off the top of my head. |
Hi, The query below works: But if we want to use parameters, like below: |
I have a query where I'm trying to retrieve a list of posts that have a post type that is in an array. For example...
I'm trying to use query parameters for this so I started off with the following:
and pass in the array ['post', 'comment']. However I get an error stating there's a problem with my syntax near $1. I tried wrapping the $1 in parenthesis and while this query executed, it returned no rows while my original query (without parameters) would return at least 5 rows.
I'm wondering what PG does with array parameters that's causing this query to return 0 rows. I would expect that if I passed an array as a parameter that I should be able to use it with an IN operator. Am I missing something or is this perhaps a bug?
The text was updated successfully, but these errors were encountered: