Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 3AA16632495 for ; Sun, 26 Jul 2009 14:34:37 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 40711-03 for ; Sun, 26 Jul 2009 17:34:26 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-ew0-f226.google.com (mail-ew0-f226.google.com [209.85.219.226]) by mail.postgresql.org (Postfix) with ESMTP id 82A2B6322B4 for ; Sun, 26 Jul 2009 14:34:26 -0300 (ADT) Received: by ewy26 with SMTP id 26so890904ewy.19 for ; Sun, 26 Jul 2009 10:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=sk2AMGUuZLY/VQD7/cNMb+j5K/6K1pLRXMksyoZKUAo=; b=de+3/EL/jKXUwp/w112zrbxzVS6j3d6cqqo7w2iHU1atddW93i75hms/kZLLFM+Bwh mROPm5tXLkaeolxN2rvhZN5KG6kE9Xlf825+Xgno56RW4Kvd5QvlhG/Olv/lHkGB5ztU F9slKcR1LXkB9i5S4h+5GEyNFB742Lar+8HBo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=KYfUzPMaHnc6iiMTpIpX02YYBcwGF+ew9WakVCH5QPc9iakoziflY3Ubv+DnYxHFCg jODcRjrqU2lYeJVVjnopEz3tMlpf0Lrix3hggxvDk2tOXJ/tUImn+8T0bYDFmA+EZd8X Q7XM6VRIuq3IYp79kT+av4UABwmY5T6Fg/x6M= MIME-Version: 1.0 Received: by 10.210.140.11 with SMTP id n11mr1486037ebd.88.1248629664745; Sun, 26 Jul 2009 10:34:24 -0700 (PDT) In-Reply-To: <194f62550907261020p569d3440s17f4edbfd88b0ba4@mail.gmail.com> References: <194f62550907260910x5a286204g3280e4eb5e583cca@mail.gmail.com> <27956.1248625117@sss.pgh.pa.us> <194f62550907261020p569d3440s17f4edbfd88b0ba4@mail.gmail.com> Date: Sun, 26 Jul 2009 11:34:24 -0600 Message-ID: Subject: Re: Implicit sequence with start value? From: Scott Marlowe To: Clemens Eisserer Cc: pgsql-general@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=-10 required=5 tests=none X-Spam-Level: X-Archive-Number: 200907/1079 X-Sequence-Number: 150842 On Sun, Jul 26, 2009 at 11:20 AM, Clemens Eisserer wr= ote: > Hi Tom, > >> regression=3D# alter sequence foo_bar_seq start with 1000; >> ALTER SEQUENCE > Completly forgot about that possibility, thanks a lot :) > > What still puzzles me is how to get the sequence value applied. > MySQL's auto_increment simply ignores whatever value is supplied to > it, however postgres seems to insert the value instead of the next > sequence value, if one is supplied: > >> CREATE TABLE custtype (key SERIAL PRIMARY KEY NOT NULL, name VARCHAR(127= ) NOT NULL, =A0short VARCHAR(4)); >> ALTER SEQUENCE custtype_key_seq START WITH 10000;"); >> INSERT INTO custtype VALUES(0, 'test', 'ta'); >> >> =A0key | =A0 =A0 =A0name =A0 =A0 =A0| short >> -----+----------------+------- > =A0> =A00 =A0 | test =A0 =A0 =A0| ta > > Of course, under normal circumstances it would be no problem to insert > a nextval() however I am using an updateable JDBC ResultSet. > Any idea how I can force the sequence's nextval() value into the key > column using ResultSets? > > Thank you in advance, Clemens Two methods: 1: Don't include the column in the insert: INSERT INTO custtype ("name",short) VALUES('test', 'ta'); 2: Use the DEFAULT keyword: INSERT INTO custtype (key, "name",short) VALUES(DEFAULT, 'test', 'ta');