Postgresql json like query

后端 未结 4 1675
别跟我提以往
别跟我提以往 2021-02-02 06:02

I have the following table called module_data. Currently it has three rows of entries:

                id                               data
0ab5203b-9157-4934-         


        
相关标签:
4条回答
  • 2021-02-02 06:17

    One other option which may be sufficient for other people who've found this page is to just cast the column to text type. Eg

    select * from module_data where data::text like '%Board%'
    

    Note though, this will search over the entire json and should only be used if you can guarantee the other fields won't be a problem.

    0 讨论(0)
  • 2021-02-02 06:26

    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%'
    
    0 讨论(0)
  • 2021-02-02 06:35

    I Think it should be like

    select * from module_data where data->>'$."title"' like '%Board%'
    

    then only it worked for me.

    0 讨论(0)
  • 2021-02-02 06:42

    I found the following is more straight-forward and easier for jsonb type of columns:

    select * from table_name
    where 
    column_name::text like '%Something%'
    

    Found a good article on more examples and implementations: https://www.compose.com/articles/faster-operations-with-the-jsonb-data-type-in-postgresql/

    Hope it helps!

    0 讨论(0)
提交回复
热议问题