@@Fetch_status 在 postgreSQL 中

@@Fetch_status in postgreSQL

我正在将我的数据库从 MS SQL 服务器转移到 PostgreSQL,我遇到了这个触发器的问题:

CREATE TRIGGER added_clients ON client
FOR INSERT
AS
BEGIN
DECLARE cursor_inserted CURSOR
FOR SELECT name, surname FROM inserted;
OPEN cursor_inserted
DECLARE @name varchar(15), @surname varchar(20)
FETCH NEXT FROM cursor_inserted INTO @name, @surname
WHILE @@FETCH_STATUS = 0
BEGIN
print 'Added: '+@name+' '+ @surname
FETCH NEXT FROM cursor_inserted INTO @name, @surname
END
CLOSE cursor_inserted
DEALLOCATE cursor_inserted
END
GO

@@FETCH_STATUS 在 postgreSQL 中的等价物是什么?

这是 PostgreSQL 的游标文档

http://www.postgresql.org/docs/current/static/plpgsql-cursors.html

遍历游标:

[ <<label>> ]
FOR recordvar IN bound_cursorvar [ ( [ argument_name := ] argument_value [, ...] ) ] LOOP
    statements
END LOOP [ label ];

找到了 PostgreSQL 中的 @@fetch_status 等价物。

您将在此处找到更多信息:https://www.postgresql.org/docs/9.1/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-DIAGNOSTICS

在你的触发器中,你只需要写WHILE (FOUND) 而不是@@fetch_status = 0。

希望我的回答对您有用。