I have the following table called module_data. Currently it has three rows of entries:
id data 0ab5203b-9157-4934-8aba-1512afb0abd0 {"title":"Board of Supervisors Meeting","id":"1i3Ytw1mw98"} 7ee33a18-63da-4432-8967-bde5a44347a0 {"title":"Board of Supervisors Meeting","id":"4-dNAg2mn6o"} 8d71ca35-74eb-4751-b635-114bf04843f1 {"title":"COPD 101", "id":"l9O0jCR-sxg"}
Column data's datatype is jsonb
. I'm trying to query it using like
operator. Something like the following:
SELECT * FROM module_data WHERE title LIKE '%Board%';
I've been looking at the jsonb
support and there doesn't seem to be a like
operator. If anyone has any advice.
Postgres is a relational database that allows you to combine relational and non-relational data effortlessly, giving users/applications flexibility in accessing and handling the data. Additionally, Postgres includes native support for querying and processing JSON data. Read along to learn more about Postgres JSON Query. What is JSON Data?
In PostgreSQL, path expressions are implemented as the jsonpath data type and can use any elements described in Section 8.14.7. JSON query functions and operators pass the provided path expression to the path engine for evaluation. If the expression matches the queried JSON data, the corresponding JSON item, or set of items, is returned.
2. Basics of PostgreSQL's JSONB data type We'll first look at some basic operations for inserting and updating JSONB columns. Use the || operator to concatenate existing data with new data. The operator will either update or insert the key to the existing document.
The result has been that all of the JSON data has been displayed in a single column. PostgreSQL includes some functions that let you expand the JSON fields and display them in different rows. The JSONB_EACH function will display each key and value pair as elements. It will split each key into separate rows.
If the data column is text type, then use ->>
on cast:
select * from module_data where data::json->>'title' like '%Board%'
If it's already json:
select * from module_data where data->>'title' like '%Board%'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With