Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 98C801337B4F for ; Mon, 6 Dec 2010 12:21:40 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 81167-04 for ; Mon, 6 Dec 2010 16:21:33 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp.iq.pl (smtp.iq.pl [86.111.241.19]) by mail.postgresql.org (Postfix) with ESMTP id DD9C51337B39 for ; Mon, 6 Dec 2010 12:21:32 -0400 (AST) Received: (qmail 5885 invoked from network); 6 Dec 2010 16:21:32 -0000 Received: from unknown (HELO thebe.iq.pl) ([86.111.241.3]) (envelope-sender ) by iq.pl with SMTP for ; 6 Dec 2010 16:21:32 -0000 Received: from 104-219.echostar.pl (104-219.echostar.pl [213.156.104.219]) by horde.iq.pl (Horde MIME library) with HTTP for ; Mon, 06 Dec 2010 17:21:31 +0100 Message-ID: <20101206172131.cjlul2oggc0848so@horde.iq.pl> Date: Mon, 06 Dec 2010 17:21:31 +0100 From: mike@if-then-else.pl To: grandebuzon@gmail.com Cc: pgsql-sql@postgresql.org Subject: Re: The best option to insert data with primary id References: <20101206162725.o3q9xfug2ioo08g8@horde.iq.pl> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-2; format="flowed" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable User-Agent: IQ WebMail 2.0 X-Originating-IP: 213.156.104.219 X-Remote-Browser: Mozilla/5.0 (X11; U; Linux x86_64; en-GB; rv:1.9.2.12) Gecko/20101027 Ubuntu/10.04 (lucid) Firefox/3.6.12 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.6 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7 X-Spam-Level: X-Archive-Number: 201012/32 X-Sequence-Number: 34868 Quoting - : > 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=B3 Roszka mike@if-then-else.pl