0

I am trying to query a table which a json column

select * 
from subscription 
where extras->>'end_date' > 1592424632;

this errors out saying

ERROR: invalid input syntax for integer: "end_date"

I have tried type casting

select * 
from subscription 
where extras->>'end_date'::int4 > 1592424632;

ERROR: invalid input syntax for integer: "end_date"

and extras column sample input looks like

{"end_date": 1592425146, "capacity": 1, "start_date": 1584562746, "devices": "", "quantity": 10}
1

1 Answer 1

4

You need parentheses. The cast operator :: has a higher precedence than the -> operator. So extras->>'end_date'::int4 is parsed as extras->> ('end_date'::int4) which is the reason for the error.

select * 
from subscription 
where (extras->>'end_date')::int4 > 1592424632
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.