我要创建此函数,但变量view_size
被视为列。
我收到错误消息column view_size don't exists.
为什么?
如果我改变了上下文,它就可以了(例如:只进行查询,被视为变量)。
CREATE OR REPLACE FUNCTION create_view(view_size INTEGER) RETURNS VOID
AS $$
BEGIN
CREATE VIEW token_relation
AS
SELECT * FROM textblockhastoken
ORDER BY textblockid, sentence, position
LIMIT view_size;
END
$$
LANGUAGE plpgsql;
答案 0 :(得分:2)
请改为尝试:
CREATE OR REPLACE FUNCTION create_view(view_size INTEGER) RETURNS VOID
AS $$
BEGIN
EXECUTE 'CREATE VIEW token_relation
AS
SELECT * FROM textblockhastoken
ORDER BY textblockid, sentence, position
LIMIT ' || view_size;
END
$$
LANGUAGE plpgsql;