looping through query to update column

From: Jean-Christophe Roux <jcxxr(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: looping through query to update column
Date: 2006-10-12 23:13:23
Message-ID: 20061012231323.26267.qmail@web35305.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,
I am trying to loop through a table to update one column

create or replace function foo() returns integer as $$
declare
rec RECORD;
row integer := 0;
begin
for rec in select * from table loop
update rec set recordid = row;
row++;
end loop;
return 0;
end;
$$ language plpgsql

In pgadmin, I am getting the following error message, but that does not help me much:
ERROR: syntax error at or near "$1" at character 9
QUERY: update $1 set recordid = $2
CONTEXT: SQL statement in PL/PgSQL function "foo" near line 6

Thanks for any help
JCR

Browse pgsql-general by date

  From Date Subject
Next Message Robert L Mathews 2006-10-12 23:36:43 Re: Storing images in PostgreSQL databases (again)
Previous Message Jonathan Vanasco 2006-10-12 23:12:10 Re: bad error message