Re: Sequence and nextval problem

Поиск
Список
Период
Сортировка
От Scott Marlowe
Тема Re: Sequence and nextval problem
Дата
Msg-id dcc563d10811241120h1962b3f1vb59c6e862381631@mail.gmail.com
обсуждение исходный текст
Ответ на Sequence and nextval problem  (Tk421 <vrobador@gmail.com>)
Список pgsql-sql
On Mon, Nov 24, 2008 at 12:12 PM, Tk421 <vrobador@gmail.com> 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?

The sequence should be set to the next value available after loading
data and then left alone.  You can set the value with
setval('seqname');  It looks to me like if you did a few more inserts,
you'd hit the value of 6 for your id field and your insert would fail
until the sequence got past 7 then it would start working.

Note that in postgresql, the value given by nextval is the next value
of the sequence, not max(val)+1 as max(val)+1 doesn't scale / isn't
really transaction safe.


В списке pgsql-sql по дате отправления:

Предыдущее
От: Tk421
Дата:
Сообщение: Sequence and nextval problem
Следующее
От: ries van Twisk
Дата:
Сообщение: Re: Sequence and nextval problem