0

I have a text column like this:

{
   "addFee":0,
   "addFeeTotal":0,
   "addFeeType":0,
   "addFeeUsers":0,
   "addFeeVat":0,
   "addFeeYears":0,
   "priceTotal":0,
   "unit1":"db",
   "unit1Value":5,
   "unit2":null,
   "unit2Value":0
}

I'd like list the priceTotal values, but

I got "cannot extract elements from a scalar" for this:

select p 
from web.order_details, 
   jsonb_array_elements_text(calculatedproductprice::jsonb -> 'priceTotal') as p

And got "function jsonb_array_elements_text(text) does not exist" for this:

select js ->> 'priceTotal' as p 
from web.order_details, 
   jsonb_array_elements_text(calculatedproductprice) as js

I ran out of ideas, but maybe this is not a valid json data?

1 Answer 1

1

Well, your JSON isn't an array, so obviously jsonb_array_elements isn't the right function to use.

As the key you are interested in, is a top-level key, you don't need anything else than just the ->> operator:

select calculatedproductprice::jsonb -> 'priceTotal' as price_total
from web.order_details
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.