Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Negating the ?& JSON operator

Is there a way to negate the ?& operator in Postgres? The operators table in the postgres docs says that ?&is equivelent to "Do all of these key/element string exist?"

What I want to do is return rows based on whether all keys in an array do not exist. So something like

SELECT * FROM mytable WHERE NEGATE_THIS(jsoncolumn ?& ['v1', 'v2'])

I can't see a specific operator in the documents, is there a way to do this?

like image 628
James Hay Avatar asked Sep 10 '26 17:09

James Hay


1 Answers

How about (assuming you want all rows where none of the keys exist)

WHERE NOT (jsoncolumn ?| ['v1', 'v2'])

?| is "Do any of these key/element strings exist?"

like image 109
Thilo Avatar answered Sep 12 '26 16:09

Thilo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!