From: | ries van Twisk <pg(at)rvt(dot)dds(dot)nl> |
---|---|
To: | Tk421 <vrobador(at)gmail(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Sequence and nextval problem |
Date: | 2008-11-24 21:21:40 |
Message-ID: | 0FCB821D-C666-4FB9-B9FE-BA7B9EECE8C5@rvt.dds.nl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Nov 24, 2008, at 2:12 PM, Tk421 wrote:
> Hello everybody.
>
> I've got an vb aplication that uses an Access database. I'm trying
> to convert the database to postgres. The conversion was done ok, but
> i've got a little problem that i don't know how to solve. Let's see
> if anyone can help me.
>
> The conversion from access database to postgres worked fine.
> Everithing it's ok. But now, when i use my database i've found a
> problem with sequences. In the conversion, the "autonumeric" fields
> from access have been converted to sequences, everithing ok in a
> first view. The problem comes because the autonumeric fields in
> access always return the last value of the table +1, but postgres
> no. Postgres returns "lost" (i don't know how to call them) values.
> An example.
>
> This is an example of a table:
>
> code | description
> ----- | ------------
> 1 | desc 1
> 2 | desc 2
> 6 | desc 6
> 7 | desc 7
>
>
> In access if i execute "INSERT INTO table (description) VALUES
> ('desc 8'), the result row is 8 | desc 8
> But in postgres the same query te result row is 3 | desc 8
>
> My question is, can i do something to make ANY sequence to take
> the last value from his associated table, and not a "lost" value?
>
> Thank you very much
>
>
This sounds like if the start of the sequence is set incorrectly:
Try this : SELECT setval('NAME OF SEQUENCE', SOME_INTEGER, true);
btw, you should also not expect a specific value from the sequence
except that you will always get the next value from the sequence.
it's also generally a bad idea to do select max(someid)+1 from table.
The whole concept of a sequence is thus much better.
Ries
From | Date | Subject | |
---|---|---|---|
Next Message | Craig Ringer | 2008-11-25 04:35:51 | Re: Sequence and nextval problem |
Previous Message | Scott Marlowe | 2008-11-24 19:20:25 | Re: Sequence and nextval problem |