Re: The best option to insert data with primary id - Mailing list pgsql-sql

From mike@if-then-else.pl
Subject Re: The best option to insert data with primary id
Date
Msg-id 20101206172131.cjlul2oggc0848so@horde.iq.pl
Whole thread Raw
In response to The best option to insert data with primary id  (- <grandebuzon@gmail.com>)
List pgsql-sql
Quoting - <grandebuzon@gmail.com>:

> I know you can skip SEQUENCE - ((SELECT nextval ('seq_table')) do not put
> this in the query, my question was that such concurrency, and ids
> omitted  which can not be inserted but increased with SEQUENCE ?

In the initial message you have been wondering, if you should be worried
about "wasted" sequence tokens.  You have mentioned, that your primary key
is of type int8 and so is the sequence range.  Do you really expect as many
records and/or insert queries?

If so, consider the id column int8 DEFAULT NULL and an AFTER INSERT trigger
function that would take a nextval of the sequence and update the id
accordingly once the record *has been actually inserted* instead of poking
the sequence each time you *are going to insert* something.

I am pretty sure, that the table is locked to prevent inserts until the
after-insert-trigger is finished.

Cheers,
   -Mike

--
Michał Roszka
mike@if-then-else.pl



pgsql-sql by date:

Previous
From: mike@if-then-else.pl
Date:
Subject: Re: The best option to insert data with primary id
Next
From: bricklen
Date:
Subject: Re: Union Question