sequence dump/reload

From: Oleg Broytmann <phd(at)sun(dot)med(dot)ru>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: sequence dump/reload
Date: 1999-02-08 10:29:44
Message-ID: Pine.SOL2.3.96.SK.990208132343.982A-100000@sun.med.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)earthling(dot)net
Programmers don't die, they just GOSUB without RETURN.

Browse pgsql-hackers by date

  From Date Subject
Next Message Pascal GEND 1999-02-08 10:56:42 writing a JAVA interface for postgres
Previous Message Michael Meskes 1999-02-08 10:28:31 Embedded SQL question