gpt4 book ai didi

sql - postgresql 中的 EXECUTE 语法错误

转载 作者:行者123 更新时间:2023-11-29 12:25:11 25 4
gpt4 key购买 nike

我想使用 execute 执行以下查询,它与 select 完美配合,但是当我在触发器中调用它时,我收到此错误“错误:查询没有结果数据的目的地”。我试过 perform 但它不起作用。 select 中的函数在表中插入行。

select insert_new_grade('title0', return3_6(0), return3_6(1), return3_6(2), s.code)
FROM "student" as s
where find_st(s.grade)>=5;

所以我想到了 EXECUTE,但我遇到了语法错误。这是我的尝试:

execute 'insert_new_grade('title0', return3_6(0), return3_6(1), return3_6(2), s.code)
FROM "student" as s
where find_st(s.grade)>=5';

谁能告诉我我做错了什么?还是有其他想法可以使查询在触发器功能中起作用?提前致谢..

这是触发器:

CREATE OR REPLACE FUNCTION insert_d() 
RETURNS TRIGGER AS $$
BEGIN
select insert_new_grade('title0', return3_6(0), return3_6(1), return3_6(2), s.code)
FROM "student" as s
where find_st(s.grade)>=5;

return new;
END;
$$ LANGUAGE plpgsql;

这是插入函数:

CREATE OR REPLACE FUNCTION insert_new_diploma(title0 character(100), prof0 character(11), prof1 character(11)) 
RETURNS VOID AS $$
BEGIN
INSERT INTO "d_table"(thes0, title, grade, prof, secProf)
VALUES (null, title0, null, prof0, prof1);
END
$$
LANGUAGE 'plpgsql';

最佳答案

41.5.2. Executing a Command With No Result

Sometimes it is useful to evaluate an expression or SELECT query butdiscard the result, for example when calling a function that hasside-effects but no useful result value. To do this in PL/pgSQL, usethe PERFORM statement

强调我的。

内部函数将 select 更改为 perform

关于sql - postgresql 中的 EXECUTE 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43666856/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com