SuperM4n SuperM4n - 1 month ago 16
SQL Question

@@Fetch_status in postgreSQL

I'm transfering my database from MS SQL Server to PostgreSQL and I have a problem with this trigger:

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


What is the equivalent of @@FETCH_STATUS in postgreSQL?

Answer

Here is the Cursor documentation for PostgreSQL

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

Looping through a cursor:

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