I have a table called messages which has a jsonB column called headers to store message headers. It looks like this:
[
{
"name":"Cc",
"field":{
"name":"Cc",
"value":"\"[email protected]\" <[email protected]>",
"length":null,
"charset":"UTF-8",
"element":null,
"address_list":{
"addresses":[
{
"data":{
"raw":"\"[email protected]\" <[email protected]>",
"error":null,
"group":null,
"local":"abc",
"domain":"gmail.com",
"comments":[
],
"display_name":"[email protected]",
"obs_domain_list":null
},
"parsed":true
}
],
"group_names":[
]
}
},
"charset":"UTF-8",
"field_order_id":14,
"unparsed_value":"\"[email protected]\" <[email protected]>"
},
{
"name":"Message-ID",
"field":{
"name":"Message-ID",
"uniq":1,
"value":"<[email protected]>",
"length":null,
"charset":"UTF-8",
"element":{
"message_ids":[
"[email protected]"
]
}
},
"charset":"UTF-8",
"field_order_id":16,
"unparsed_value":"<[email protected]>"
},
{
"name":"Subject",
"field":{
"name":"Subject",
"value":"Re: test email",
"errors":[
],
"length":null,
"charset":"UTF-8",
"element":null
},
"charset":"UTF-8",
"field_order_id":19,
"unparsed_value":"Re: test email"
}
]
I want search records where 'name' = 'Subject' and 'unparsed_value' like %test% and return the result in Rails 6.0.2?
I'm trying the below mention code:
messages.where("headers @> '[{\"name\": \"Subject\"}, {\"unparsed_value\" LIKE \"%test%\"}]'")
But it's throwing error!