You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've got a .raw query with the following filter on a JSONB column named data: WHERE data ->> 'key' IN %s
The %s is populated by taking the list and passing it in as follows: ModelName.objects.raw(query_with_params, [tuple(list_of_values)])
When viewing the debug pane the SQL generated for the relevant section looks like: WHERE data ->> 'key' IN ('value_1', 'value_2', 'value_3')
When trying to view the explain of the query a 500: Internal Server Error results due to a pscyopg2.errors.syntax error on the following SQL: data ->> 'key' IN ARRAY['value_1','value_2','value_3',...
It looks like there's some issue in what populates the params for this line where the passed in tuple is being turned back into a list as lists are turned into ARRAYS not collections.
I was able to get it to work by with the following changes: WHERE data ->> 'key' = ANY(%s)
and ModelName.objects.raw(query_with_params, [list_of_values]) where type(list_of_values) is <class 'list'>
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
I've got a .raw query with the following filter on a JSONB column named
data
:WHERE data ->> 'key' IN %s
The
%s
is populated by taking the list and passing it in as follows:ModelName.objects.raw(query_with_params, [tuple(list_of_values)])
When viewing the debug pane the SQL generated for the relevant section looks like:
WHERE data ->> 'key' IN ('value_1', 'value_2', 'value_3')
When trying to view the explain of the query a 500: Internal Server Error results due to a pscyopg2.errors.syntax error on the following SQL:
data ->> 'key' IN ARRAY['value_1','value_2','value_3',...
It looks like there's some issue in what populates the params for this line where the passed in tuple is being turned back into a list as lists are turned into ARRAYS not collections.
I was able to get it to work by with the following changes:
WHERE data ->> 'key' = ANY(%s)
and
ModelName.objects.raw(query_with_params, [list_of_values])
wheretype(list_of_values)
is <class 'list'>The text was updated successfully, but these errors were encountered: