"Hari Patel" <hariwise@gmail.com> writes:
> CREATE function set_sequence_ids() RETURNS INTEGER AS '
> DECLARE
> arg INTEGER;
> BEGIN
> select into arg max(id) from foo;
> select setval('foo_id_seq', 10);
> return arg;
> END;
> ' LANGUAGE 'plpgsql';
> I get the following error in psql.
> psql:func.sql:9: ERROR: syntax error at or near "foo_id_seq" at charact
> er 152
> psql:func.sql:9: LINE 6: select setval('foo_id_seq', 10);
> psql:func.sql:9: ^
You've got a quoting problem: either double the quotes embedded in the
function body, or use dollar quotes ($$) to surround the function body
instead of plain quotes (').
BTW, seems like the above is wrong anyway: don't you want to set the
sequence to arg+1, rather than constant 10?
regards, tom lane