How to remove or escape the double quotes while returning table from PostgreSQL function

烂漫一生 提交于 2019-12-25 02:53:35

问题


Hello I have a PostgreSQL function which returns table


-- Function: stloadstoryview(integer)

-- DROP FUNCTION stloadstoryview(integer);

CREATE OR REPLACE FUNCTION stloadstoryview(IN luserid integer)
  RETURNS TABLE(stid integer, stname text, stowner character varying, stbegin date, stend date) AS
$BODY$
Begin

    Return query
    Select dbStory.stID, dbStory.stName, (Select usName from dbUser where usID = dbStory.stOwner):: Varchar(30), dbStory.stBegin, dbStory.stEnd from dbStory 
        where dbStory.stID in (Select dbStoryRights.stID from dbStoryRights where usID = lUserID)
        Order by dbStory.stName;
End;
$BODY$
  LANGUAGE plpgsql STABLE
  COST 100
  ROWS 1000;
ALTER FUNCTION stloadstoryview(integer)
  OWNER TO postgres;

which will return


"(2,"Story 201",admin,2015-01-01,2015-06-30)"
"(1,Story101,admin,2015-03-01,2015-04-30)"

In the first row it will return "Story 201" with quotes and in second row "Story101" which is unquoted.....

If the spaces in between the values its returning quotes so how to get all values in that column without qoutes.Having spaces in the values.


回答1:


It looks like you are querying the function directly which will return a single column containing all the values returned from the function.

Try selecting the fields from the function instead:

SELECT *
FROM stloadstoryview(1);

Which will return data in separate columns:

"stid", "stname", "stowner", "stbegin", "stend"
2, Story 201, admin, 2015-01-01, 2015-06-30
1, Story101, admin, 2015-03-01, 2015-04-30


来源:https://stackoverflow.com/questions/29281371/how-to-remove-or-escape-the-double-quotes-while-returning-table-from-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!