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

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -