Casting a variable as array in a query

53 views
Skip to first unread message

Sencer Hamarat

unread,
Jul 26, 2022, 3:36:39 PM7/26/22
to django...@googlegroups.com
I'm having a problem with this query:

I believe, 

Q(bundle__contains=OuterRef("book_id"))

part of the query is expecting an array instead of single value.

I'm getting this error:


ProgrammingError: operator does not exist: jsonb @> bigint
LINE 1: ...lisher"."book_id") OR U0."bundle" @> ("publisher_...
                                                             ^
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.



Is there a way to handle this error? How can I cast the value into an array within the query?

Sencer Hamarat

unread,
Jul 27, 2022, 6:07:59 AM7/27/22
to django...@googlegroups.com
Ok, I figure out how to do that.

There is a Cast method in django, but casting is not just enough. Also need to use Concat method to convert OuterRef value to an array, such as:

Q(bundle__contains=Cast(Concat(OuterRef("book_id"), []), JSONField()))

That's do the trick.


26 Tem 2022 Sal 22:35 tarihinde Sencer Hamarat <sencer...@gmail.com> şunu yazdı:
Reply all
Reply to author
Forward
0 new messages