alter sequence in a function - Mailing list pgsql-admin

From Julio Leyva
Subject alter sequence in a function
Date
Msg-id BAY120-W180EC0773E6E0BC38E448DA10C0@phx.gbl
Whole thread Raw
Responses Re: alter sequence in a function
Re: alter sequence in a function
List pgsql-admin
Hi all

I'm trying to create a function that alters a sequence

This what I'm doing

create or replace function updatesafe()  returns integer AS $$
DECLARE
maxseq integer;
alterseq varchar(256);
thumb integer;
newvalue integer;
BEGIN
newvalue := 10010;
  maxseq := (select max(safeoperationid) from safeopencloseoperation);

    if (maxseq < 500) then
      return 3000;

   else
    execute 'ALTER sequence safeopencloseoperation_id_seq restart with ' || 'newvalue ' ;
    return 10000;
 END IF;
END;
$$ language plpgsql

It compiles ok but when I call the function
it gives me this error

 ALTER sequence safeopencloseoperation_id_seq restart with newvalue
CONTEXT:  PL/pgSQL function "updatesafe" line 17 at execute statement
LINE 1: ...equence safeopencloseoperation_id_seq restart with newvalue


However when I change the alter sequence for this

ALTER sequence safeopencloseoperation_id_seq restart with 10000 ;

The function is ok,

It means that we can't use such a utility inside a function? I mean replacing a value for a variable?

Thanks for any suggestion





pgsql-admin by date:

Previous
From: Namık Güngör
Date:
Subject: (konusuz)
Next
From: ngaleyev@wavelengthmail.com
Date:
Subject: hot restart of posgtresql