postgres“返回表”返回一个字符串

时间:2010-07-23 08:15:00

标签: postgresql

我使用Postgres上的SQL语言使用RETURNS TABLE命令返回一个表:

CREATE OR REPLACE FUNCTION procreadbudget()
  RETURNS TABLE(budgetmonth character, budgetincome numeric, budgetexpense numeric) AS
$BODY$
SELECT budget_month, budget_income, budget_expense FROM budget ORDER BY unique_id;
$BODY$
  LANGUAGE 'sql' VOLATILE

所有数据都以逗号分隔的字符串形式返回,而不是以表格形式返回:

"(Jan,1123,1201)"
"(Feb,1098,996)"
"(Mar,1545,1345)"
"(Apr,1564,1952)"
"(May,1123,990)"
"(Jun,1345,1234)"
"(Jul,1234,878)"
"(Aug,1139,1187)"
"(Sep,1076,1123)"
"(Oct,873,956)"
"(Nov,1298,1423)"
"(Dec,1123,1324)"

请提出任何建议, 麦克

2 个答案:

答案 0 :(得分:7)

使用

SELECT * FROM procreadbudget();

而不是

SELECT procreadbudget();

答案 1 :(得分:0)

这样做:

select t.budgetmont,
       t.budgetincome,
       t.budgetexpense
from procreadbudget() as t