Answer the question
In order to leave comments, you need to log in
PostgreSQL->jsonb how to use field aliases in a condition?
Hello everyone, especially PostgreSQL gurus.
There is a request:
SELECT jsonb_array_elements(documents->'policy') AS policies
FROM (
SELECT jsonb_array_elements(documents) AS documents
FROM test
) AS policy
--WHERE policies->>'date_from' > '1424621049'
Answer the question
In order to leave comments, you need to log in
I decided so, but there may still be options and suggestions. And then writing such a structure in a framework through ORM is somehow not "ethical" or something.
SELECT *
FROM
(
SELECT jsonb_array_elements(documents->'policy') AS policies
FROM (
SELECT jsonb_array_elements(documents) AS documents
FROM test
) AS policy
) AS result
WHERE policies->>'date_from' > '1424621049'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question