Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a table which has a column called warnings. the column value for 2 rows is shown bellow

                             warnings
-------------------------------------------------------------------
 {"isNew":false,"fieldWarnings":[],"dupId":null,"conflictIds":[]}
 {"isNew":false,"fieldWarnings":[],"dupId":3763,"conflictId":null}

I want an sql statement that will select the top row but not the bottom row. i tried this sql query but it selects both rows

select warnings from table where cast(warnings->>'dubId' AS TEXT) is null;
share|improve this question

1 Answer 1

You have dubId in your query but the JSON property is dupId. I think you've just got a typo!

Try this instead:

select warnings from table where cast(warnings->>'dupId' AS TEXT) is null;

Also, the ->> operator returns the field value as text already so you shouldn't need the cast:

select warnings from table where warnings->>'dupId' is null;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.