9

I have a column of text type be contain json value.

{"summary":"this is a example","url":"stackoverflow.com"}

How can I extract 'url' json field of column in postgres with query?

I used of following query:

 SELECT jvalue->>'url' From table;

With my query, I get following error.

SQL Error [42883]: ERROR: operator does not exist: text ->> unknown Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts. org.postgresql.util.PSQLException: ERROR: operator does not exist: text ->> unknown Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.

1 Answer 1

24

You could use the -> operator:

SELECT '{"summary":"this is a example","url":"stackoverflow.com"}'::json->'url';
Sign up to request clarification or add additional context in comments.

6 Comments

what if i have a json value like, {"summary":"this is a example","uri" : [{"url":"stackoverflow.com"}]}, how to get url
note that it will display "stackoverflow.com" instead of stackoverflow.com. So it includes quotation marks
Use data::json->>'url' if you don't want double quotes around string. postgresql.org/docs/current/functions-json.html
What if the value is a json string: SELECT '"{\"summary\":\"this is a example\",\"url\":\"stackoverflow.com\"}"'
The missing sauce I was missing was not -> but the ::json part, because it's stored in a text column.
|

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.