sequence dump/reload

Поиск
Список
Период
Сортировка
От Oleg Broytmann
Тема sequence dump/reload
Дата
Msg-id Pine.SOL2.3.96.SK.990208132343.982A-100000@sun.med.ru
обсуждение исходный текст
Список pgsql-hackers
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
justGOSUB without RETURN.
 



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Oleg Broytmann
Дата:
Сообщение: Re: [HACKERS] Oops, I seem to have changed UNION's behavior
Следующее
От: Pascal GEND
Дата:
Сообщение: writing a JAVA interface for postgres