sql - query a json key in postgres json field -


say have in postgres stored in json field called “data” this

{     "custa": {         "name": "customer a",     },     "custb": {         "name": "customer b",     },     "custc": {         "name": "customer c",     } } 

how can query return record contains key “custa” ? or better value of “custa” "name": "customer a"

trying cant use keyword key

select * invoices data->>key = 'custa'; 

select '{     "custa": {         "name": "customer a"     },     "custb": {         "name": "customer b"     },     "custc": {         "name": "customer c"     } }'::json#>>'{custa}';            ?column? ------------------------------  {                           +          "name": "customer a"+      } (1 row) 

note: have trailing commas after name:customer x, not proper json. query, like:

select data#>>'{custa}' invoices; 

or, if data isn't json field:

select data::json#>>'{custa}' invoices; 

i don't understand why invoice have more 1 customer though.

-g


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -