Hey all! I'm looking for a way to run a search aga...
# help
a
Hey all! I'm looking for a way to run a search against a jsonb column's values only, and not the keys. So for example given a column called
info
with data like:
{ topic: "postgres" }
, I'd like for this row to be returned if the provided search value string contains
"postgres"
but not if it includes
"topic"
I was able to create a new column on the table that is a concatenation of other columns to run text search against that generated column (using the docs https://supabase.com/docs/guides/database/full-text-search#searchable-columns), but so far haven't been able to figure out the syntax to do this with a jsonb column for the values only, I get the whole stringified object in there, which is ok but not ideal as some of the keys are fairly generic and shouldn't match on a text search. Thanks in advance!
n
Hello @alxndr! This thread has been automatically created from your message in #843999948717555735 a ``few seconds ago``. Pinging @User so that they see this as well! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! We have solved your problem? Click the button below to archive it.
g
This will get you an a comma separated string for the values only:
Copy code
select array_to_string(array(
select value from jsonb_each_text( 
(select myjson from messages where id = 6)
)),',');
The inner select is for my test using a table I have with jsonb and would just be a column name in the row in your case.
n
alxndr (2022-03-13)