Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Postgresql cursor loop

Status
Not open for further replies.

dbrb2

Instructor
Jul 19, 2004
121
GB
Hi,
I'm new to postgresql. I'm trying to get a function that will loops through a cursor, and update every row. I have tried various permutations of the below, but am getting syntax errors. Can anyone suggest what is wrong with the given example?


DECLARE
curs1 CURSOR
FOR
SELECT *
FROM myTable ;

BEGIN

FOR i IN curs1 LOOP

UPDATE myTable
SET field3 =
i.field1 ||
i.field2
WHERE CURRENT OF curs1;

END LOOP

This gives me the error:

ERROR: syntax error at or near "$1" at character 3
QUERY: $1

Any ideas?
END;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top