Re: Creating a sequence

Поиск
Список
Период
Сортировка
От Craig Ringer
Тема Re: Creating a sequence
Дата
Msg-id 480F6B43.8080407@postnewspapers.com.au
обсуждение исходный текст
Ответ на Creating a sequence  (Chris <cmattmiller@gmail.com>)
Список pgsql-jdbc
Chris wrote:
> That was my problem, I didn't know where or how to create the sequence.
> Got it to work now. :D
> So, should the standard practice be to create a sequence for every table?

That leads in to the synthetic vs natural primary key debate, which
isn't worth getting into here.

If you have a synthetic key on a table (a "meaningless" integer
identifier generated by the application or database) then a sequence is
an extremely good way of generating such identifiers. The use of a
sequence permits multiple concurrent inserts without risk of conflict
and without the need for locking.

You *WILL* get gaps in your primary key values, though, where
transactions have rolled back. Your application should be designed not
to care about this.

By the way, I pointed out the stupid way of setting a sequence start
value. What I should've written was:

CREATE SEQUENCE employee_emp_uid_seq;
SELECT setval('employee_emp_uid_seq',
    (SELECT max(emp_uid) FROM employee));

--
Craig Ringer

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Query parameters limit in postgres jdbc driver?
Следующее
От: Chris
Дата:
Сообщение: Login Roles