Home > OS >  how to access one key inside jsonb field?
how to access one key inside jsonb field?

Time:11-26

Suppose I have a table like this

     Column      │         Type         │                             Modifiers
─────────────────┼──────────────────────┼────────────────────────────────────────────────────────────────────
 id              │ integernot null default
 practice_id     │ character varying(6) │ not null
 datedatenot null
 pct_id          │ character varying(3) │
 astro_pu_items  │ double precisionnot null
 astro_pu_cost   │ double precisionnot null
 total           │ jsonb                │

I need to access total field and find the particular key. So if the key name is sub_total how can I find through query. I'm using Postgres 14.1.

I'm not able to find postgres function which can do that. So guide me here

CodePudding user response:

Use the -> Operator.

select total->'sub_total' from tablename;

https://www.postgresql.org/docs/current/functions-json.html

  • Related