在PostgreSQL中返回表的用户定义函数
我试图创建一个UDF,它返回一个包含四个值的表:在PostgreSQL中返回表的用户定义函数,sql,postgresql,user-defined-functions,Sql,Postgresql,User Defined Functions,我试图创建一个UDF,它返回一个包含四个值的表: CREATE TABLE ts_table ( id character varying, year integer, rank double precision, votes integer ); 然后,使用一个UDF,我必须返回一个表,该表由以下内容定义: 但是,当我尝试使用该命令创建UDF时,我得到 ERROR: syntax error at or near "'SELECT id,year,rank,votes
CREATE TABLE ts_table
(
id character varying,
year integer,
rank double precision,
votes integer
);
然后,使用一个UDF,我必须返回一个表,该表由以下内容定义:
但是,当我尝试使用该命令创建UDF时,我得到
ERROR: syntax error at or near "'SELECT id,year,rank,votes FROM productions NATURAL JOIN directors NATURAL JOIN ratings WHERE attr is NULL AND pid=$1 ORDER BY year;'"
LINE 2: 'SELECT id,year,rank,votes FROM productions NATURAL JOIN dir...
换线
“从productions NATURAL JOIN directors NATURAL JOIN ratings中选择id、年份、排名和投票,其中attr为NULL,pid=每年1美元;”代码>
到
从productions NATURAL JOIN directors NATURAL JOIN ratings中选择id、年份、排名和投票,其中attr为NULL,pid=每年1美元代码>
(删除单引号)将解决此问题 仔细阅读。这个密切相关的问题可能会有所帮助:@ErwinBrandstetter谢谢,我注意到我的错误有点晚了,但我想我会把它作为未来类似问题的答案。
ERROR: syntax error at or near "'SELECT id,year,rank,votes FROM productions NATURAL JOIN directors NATURAL JOIN ratings WHERE attr is NULL AND pid=$1 ORDER BY year;'"
LINE 2: 'SELECT id,year,rank,votes FROM productions NATURAL JOIN dir...