My very first PL/pgSQL procedure... - Mailing list pgsql-general

From Philippe Ferreira
Subject My very first PL/pgSQL procedure...
Date
Msg-id 43D7B751.2000407@worldonline.fr
Whole thread Raw
Responses Re: My very first PL/pgSQL procedure...
List pgsql-general
Hi,

I've got a problem with my very first PL/pgSQL procedure !
I created the following procedure, that should reconfigure a sequence :
---------------------------------------------------------------------------------------------------------------------

CREATE OR REPLACE FUNCTION seq_min(sequence_name varchar, minval
integer) RETURNS VOID AS $$
DECLARE
   current_seq integer;
BEGIN
   LOCK TABLE sequence_name IN ACCESS EXCLUSIVE MODE;
   current_seq := last_value FROM sequence_name;
   IF current_seq < minval THEN
     ALTER SEQUENCE sequence_name RESTART WITH minval;
   END IF;
END;
$$ LANGUAGE plpgsql;
---------------------------------------------------------------------------------------------------------------------


I call it from the psql interface by :
      SELECT seq_min('seq_mytable', 1029);

But PostgreSQL returns the following error (translated from french) :

ERROR:  syntax error on or near «$1» at character 13
QUERY : LOCK TABLE  $1  IN ACCESS EXCLUSIVE MODE
CONTEXT : PL/pgSQL function "seq_min" line 4 at SQL statement
LINE 1 : LOCK TABLE  $1  IN ACCESS EXCLUSIVE MODE

So it seems that PostgreSQL have troubles handling my variable
"sequence_name"...
Any idea ?

Thank you in advance,
Philippe Ferreira, France.

pgsql-general by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: Constraint that compares and limits field values
Next
From: andrew
Date:
Subject: Re: user defined function