Search Postgresql Archives

My very first PL/pgSQL procedure...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux