sqlpostgresqlset-returning-functions

Return table with json


I have the stored procedure sp_table in PostgreSQL. I wish to obtain the following result

(1,{"cola":1,"colb":"a"}) (2,{"cola":2,"colb":"b"})

With the second column in json format so that my backend can convert it into. but the sp gives me the json with double quotes.

I can only get it the way I want it when I return a column as a json as in the sp sp_only_json.

http://sqlfiddle.com/#!17/c82c1b/1

It's possible to obtain it in the desired format?


Solution

  • If the function returns a table, it should be used in the FROM clause to get separate columns as the result.

    SELECT * FROM sp_table();
    

    SQL Fiddle.