How can I do a equivalent query with "any" #2321
-
I'm trying to do a query like this, select * from posts where 'blog' = any(tags) and the schema of table posts {
id integer Auto Increment [nextval('posts_id_seq')]
body text NULL
tags text[] NULL
} I did read through the whole document, but no lucky. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Currently you can't do this directly. As an alternative you could use the select * from posts where tags @> '{"blog"}'; If you want to keep using |
Beta Was this translation helpful? Give feedback.
Currently you can't do this directly. As an alternative you could use the
cs
operator which is equivalent to@>
in PostgreSQL (not sure about the performance difference, though). The request would be/posts?tags=cs.{blog}
and it represents this query:If you want to keep using
any
you could use aFUNCTION
with the tag as parameters, or if you use that specific filter'blog' = any(tags)
a lot, then aVIEW
or a generated column could work. There's a pending enhancement related to theany
operator here #1569.