how to access one key inside jsonb field?


Suppose I have a table like this

     Column      │         Type         │                             Modifiers
 id              │ integer              │ not null default
 practice_id     │ character varying(6) │ not null
 date            │ date                 │ not null
 pct_id          │ character varying(3) │
 astro_pu_items  │ double precision     │ not null
 astro_pu_cost   │ double precision     │ not 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

>Solution :

Use the -> Operator.

select total->'sub_total' from tablename;

Leave a ReplyCancel reply