Home > Enterprise >  Why are json arrow operators not working in postgres?
Why are json arrow operators not working in postgres?

Time:10-11

I am trying to extract info from a json-type column. This is my query:

SELECT column_name -> 'key_name' FROM table.

I'm getting the following error message, referred to the arrow operator:

No operator matches the given name and argument type(s). You might need to add explicit type casts.

Same if I try with ->>.

-- edit: this is the complete error message:

ERROR:  operator does not exist: text -> unknown
LINE 1: SELECT candidate_owner_json -> 'ownerid' FROM candidate
                                    ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
SQL state: 42883
Character: 29

CodePudding user response:

I tried with this and it works:

SELECT json_array_elements(candidate_owner_json::json)->'ownerId' FROM ...
  • Related