Hello!

   I have a database, and there are a lot of tables with serial fields.
Currently, pg_dump is not generating code to reload value of correposnding
sequence.
   Is there any chance pg_dump will generate such code?

   Well, to overcome this I am trying to create a function do
initialization myself. I am trying to write:

DROP FUNCTION max_id(text, text);

CREATE FUNCTION max_id(text, text) RETURNS int2 AS
   '
      DECLARE
         table ALIAS FOR $1;
         field ALIAS FOR $2;
         myres int;
      BEGIN
         SELECT MAX(field) INTO myres FROM table;
         RETURN myres;
      END;
   '
LANGUAGE 'plpgsql';

SELECT max_id('motd', 'msg_id');

   but when I pass this to postgres I got:

DROP FUNCTION max_id(text, text);
DROP

CREATE FUNCTION max_id(text, text) RETURNS int2 AS
   '
      DECLARE
         table ALIAS FOR $1;
         field ALIAS FOR $2;
         myres int;
      BEGIN
         SELECT MAX(field) INTO myres FROM table;
         RETURN myres;
      END;
   '
LANGUAGE 'plpgsql';
CREATE

SELECT max_id('motd', 'msg_id');
ERROR:  parser: parse error at or near "$2"

   How can I write the function? I don't want to create a function for
every sequence, I want a function that takes table and field as parameters.

Oleg.
---- 
    Oleg Broytmann     http://members.xoom.com/phd2/     phd2@earthling.net
           Programmers don't die, they just GOSUB without RETURN.


Mon, 8 Feb 1999 13:29:44 +0300 (MSK)
Oleg Broytmann <phd@sun.med.ru>
sequence dump/reload