Re: Setting sequence ids after importing data
От | Hari Patel |
---|---|
Тема | Re: Setting sequence ids after importing data |
Дата | |
Msg-id | 77a93e850605081859g2f17d652j17a8f4ed7d15ceec@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Setting sequence ids after importing data (Sean Davis <sdavis2@mail.nih.gov>) |
Ответы |
Re: Setting sequence ids after importing data
Re: Setting sequence ids after importing data |
Список | pgsql-novice |
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';
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: ^
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
В списке pgsql-novice по дате отправления: