ALTER SEQUENCE ... RESTART WITH [variable] problem - Mailing list pgsql-general

From Tomi NA
Subject ALTER SEQUENCE ... RESTART WITH [variable] problem
Date
Msg-id d487eb8e0605200052n12e6e202jcd97f60020f9d6ad@mail.gmail.com
Whole thread Raw
Responses Re: ALTER SEQUENCE ... RESTART WITH [variable] problem
List pgsql-general
I need to generate a couple of dozen statements reseting my sequences
so that they're next values are greater than the biggest existing ids.
The problem is, I can't even form a statement to update one sequence.
This is what I tried:

CREATE OR REPLACE FUNCTION init_sequences() RETURNS void AS
$BODY$
DECLARE
    next_id_table1 INTEGER;
BEGIN
    SELECT INTO next_id_table1 MAX(id)+1 FROM  table1;
    ALTER SEQUENCE pk_table1 RESTART next_id_table1;
END;
$BODY$
  LANGUAGE 'plpgsql';

The problem seems to be the ALTER statement:

ERROR:  syntax error at or near "$1" at character 36
QUERY:  ALTER SEQUENCE pk_table1 RESTART  $1
CONTEXT:  SQL statement in PL/PgSQL function "init_sequences" near line 5

If I change the ALTER statement like this
    ALTER SEQUENCE pk_table1 RESTART 200;
it works. But is obviously not what I wanted.
Is there a way to get the ALTER SEQUENCE statement to use a value
stored in a variable?

t.n.a.

pgsql-general by date:

Previous
From: "dfx"
Date:
Subject: How to get recordset with CallableStatemente
Next
From: Martijn van Oosterhout
Date:
Subject: Re: ALTER SEQUENCE ... RESTART WITH [variable] problem