postgresql - Extracting key names with true values from JSONB object -
i'm trying select keys jsonb
type true
values. far managed using query feel there better way:
select json.key jsonb_each_text('{"aaa": true, "bbb": false}'::jsonb) json json.value = 'true';
what don't where
clause i'm comparing strings
. there way cast boolean
?
if yes, work truthy
, falsy
values too? (explanation of truthy
, falsy
values in javascript: http://www.codeproject.com/articles/713894/truthy-vs-falsy-values-in-javascript).
jsonb
has equality operator (=
; unlike json
), write
select key jsonb_each('{"aaa": true, "bbb": false}') value = jsonb 'true'
(with jsonb_each_text()
rely on json values' text representation).
you can include additional values, if want:
where value in (to_jsonb(true), jsonb '"true"', to_jsonb('truthy'))
in
uses equality operator under hood.
Comments
Post a Comment