15

I'm trying to understand the way the Postgresql is dealing with JSON. I've declared a two-columns table and I'd like to create a new View to get some boolean values.

So far, I've been able to get the value as text but what I'd like to get is whether the field is defined or not. For example, if the JSON has the key frameMenuData.frameElement, it should print has_frame to true.

SELECT
  customer_data->>'frameMenuData'->>'frameElement' AS has_frame,
FROM
  simple_list
WHERE
  TRUE
  AND guid='AAAA';

The above code gives me the content of that row. I need to know if customer_data->>'frameMenuData'->>'frameElement' is defined or not.

How could I achieve that ?

Thanks for your help.

1 Answer 1

18

Problem solved. It was barely easy.

SELECT (customer_data->>'frameMenuData'->>'frameElement' IS NULL) AS has_frame,
Sign up to request clarification or add additional context in comments.

1 Comment

I think you just want customer_data->>'frameMenuData' ? 'frameElement' AS has_frame see: postgresql.org/docs/current/functions-json.html and search for

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.