【发布时间】:2021-11-07 16:57:43
【问题描述】:
我是 PostgreSQL v.13 的新手,想创建一个存储过程,它将接收一个整数值,然后从表中返回结果。
我有这个:
create or replace procedure public.sp_message_template_get(
templateid int
) language plpgsql AS $$
begin
-- subtracting the amount from the sender's account
select * from public.message_template;
--commit;
end;
$$
然后我尝试使用以下方法调用它:
call public.sp_message_template_get(1);
我收到以下错误:
ERROR: query has no destination for result data
HINT: If you want to discard the results of a SELECT, use PERFORM instead.
CONTEXT: PL/pgSQL function sp_message_template_get(integer) line 6 at SQL statement
SQL state: 42601
有什么线索吗?
谢谢
【问题讨论】:
-
我很困惑,因为在 MS SQL Server 中您通常使用 SP 来返回值,所以在 PostgreSQL 中您必须使用函数来代替?那么SP的目的是什么?
-
@VAAA 好吧,Postgres 与 SQL Server 不同,在 Postgres 中,如果要返回某些内容,则需要使用函数。你需要migrate your mindset too
-
见Procedures。过程的主要好处是您可以在其中进行事务管理。对于大多数事情,您可能想要使用函数。
标签: postgresql