Trying to concat two json text fields like so:
SELECT app->>'id' || app->>'version' as foo
FROM table,
json_array_elements(applications::json) as app;
Where applications
is the data type text, results in the error:
LINE 3: SELECT app->>'id' || app->>'version' as foo
^
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
I've also tried with jsonb. What is happening here, and how should json text fields be concatenated together?
applications
really contains JSON values, it should be declared as ajsonb
column so that you don't need to cast it every time you want to do something useful with it.(app->>'id' || app)->>'version'
. Add explicit parentheses to clarify the order of the operators.