Received: from leela.one-2-one.net (leela.one-2-one.net [217.115.142.65]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g1BGCXE97566 for ; Mon, 11 Feb 2002 11:12:33 -0500 (EST) (envelope-from twanger@bluetwanger.de) Received: from [192.168.0.14] (p3E9EC01B.dip.t-dialin.net [62.158.192.27]) by leela.one-2-one.net (8.11.0/8.11.0) with ESMTP id g1BEPnR01242; Mon, 11 Feb 2002 15:25:49 +0100 Subject: Re: Sequences From: Markus Bertheau To: "Hunter, Ray" Cc: postgres sql list In-Reply-To: <59358A738F45D51186A30008C74CE250E81373@slc-exc1.ctron.com> References: <59358A738F45D51186A30008C74CE250E81373@slc-exc1.ctron.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-wpwqOzZr1xTX0bAALnhp" X-Mailer: Evolution/1.0.2 Date: 11 Feb 2002 15:22:30 +0100 Message-Id: <1013437356.3653.28.camel@entwicklung01.cenes.de> Mime-Version: 1.0 X-Archive-Number: 200202/113 X-Sequence-Number: 6541 --=-wpwqOzZr1xTX0bAALnhp Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Mon, 2002-02-11 at 14:43, Hunter, Ray wrote: > I have various sequences in my database set up for ids. My question is: > How can I get the current value of the sequence without creating a session > and using the currval function? >=20 > I would like to take the current value of the sequence and use it for a > value in an insert statement. >=20 >=20 > Example: >=20 > insert into users ( "user_id", "user_fname", "user_lname", > "user_email" ) > values ( 'current sequence', 'Ray', 'Hunter', > 'rhunter@enterasys.com' ); >=20 You probably wouldn't want to use the current but the next value of the sequence. Common solution is to set the default for the column user_id to something like nextval(users_user_id_seq"::text) and omit user_id in the insert statement such that the default value is taken. Markus Bertheau Cenes Data GmbH --=-wpwqOzZr1xTX0bAALnhp Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQA8Z9OmKNEjAb345r4RApvEAKCA8RmvTXdJU+PiuZP+SMaC1xhxjgCdGGnW Ng3J2NwGvT6rFO2wc8Wp0T0= =E4zW -----END PGP SIGNATURE----- --=-wpwqOzZr1xTX0bAALnhp--