json - How can I perform a LIKE query for a jsonb key? -
i have following jsonb structure:
{'this': '1', 'this_that': '0', 'this_and_that': '5'}
how select rows contain operator?
select * myjson j ? 'this_%'
returns 0 rows...was hoping match 'this_that' , 'this_and_that'. (note: characters following '_' potentially vary , therefore not able exact match).
your example should not work because there not implicit cast between jsonb
, text
types. can enforce casting:
select '{"this": 1, "this_that": 0, "this_and_that": 5}'::jsonb::text '%"this%';
it not clean solution. better unpacking json, , filtering on unpacked data lateral join
postgres=# select key myjson, lateral jsonb_each_text(j) key 'this\_%'; ┌───────────────┐ │ key │ ╞═══════════════╡ │ this_that │ │ this_and_that │ └───────────────┘ (2 rows)
Comments
Post a Comment