0

I'm new with PostgreSQL; I used to work with Toad for Oracle. I run the following code and can't make it work.

begin
for prueba in
(select * from a_userid)
loop
update a_userid set user_id2 = nextval('seq_userid') 
where user_id = prueba.user_id;
commit;
end loop;
end;

The error is:

************ Error **********
ERROR: error de sintaxis en o cerca de «for»
SQL state: 42601
Character: 9

With Oracle it used to work that way. I don't know where the problem is. I also tried using:

LANGUAGE 'plpgsql';

at the end... but it didn't change at all.

1 Answer 1

1

If I understand correctly what you're trying to achieve you don't need a loop for this. Simple UPDATE will do it

UPDATE a_userid
   SET user_id = nextval('seq_userid');

Here is SQLFiddle demo

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.