Re: Setting sequence ids after importing data

From: "Hari Patel" <hariwise(at)gmail(dot)com>
To: "Sean Davis" <sdavis2(at)mail(dot)nih(dot)gov>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Setting sequence ids after importing data
Date: 2006-05-09 01:59:07
Message-ID: 77a93e850605081859g2f17d652j17a8f4ed7d15ceec@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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';

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(at)mail(dot)nih(dot)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
>

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Michael Glaesemann 2006-05-09 02:20:07 Re: Setting sequence ids after importing data
Previous Message Sean Davis 2006-05-09 01:13:38 Re: Setting sequence ids after importing data