Thanks Sean. I'm trying the following after having done the import.
CREATE function set_sequence_ids() RETURNS INTEGER AS '
DECLARE
arg INTEGER;
BEGIN
select into arg max(id) from foo;
select setval('foo_id_seq', 10);
return arg;
END;
' LANGUAGE 'plpgsql';
I get the following error in psql.
psql:func.sql:9: ERROR: syntax error at or near "foo_id_seq" at charact
er 152
psql:func.sql:9: LINE 6: select setval('foo_id_seq', 10);
psql:func.sql:9: ^
setval seems to work okay outside plpgsql but I need it to do the select into.
Any help is greatly appreciated.
Thanks,
Hari
On 5/8/06, Sean Davis <sdavis2@mail.nih.gov> wrote:Hari Patel wrote:
> Hi:
>
> I am importing data from sqlite db into postgres. The tables have an id
> column that is obtained from a sequence.
>
> To preserve the foreign key relationships, I need to preserve the ids
> while importing into postgres.
>
> The problem is that after import, the sequences don't get incremented
> which leads to unique constraint violation errors further down.
> How do I fix this ?
See here in the documentation:
http://www.postgresql.org/docs/8.1/static/functions-sequence.html
SEan