Received: from wolff.to (wolff.to [66.92.219.49]) by postgresql.org (8.11.3/8.11.4) with SMTP id g1BEZTE58371 for ; Mon, 11 Feb 2002 09:35:30 -0500 (EST) (envelope-from bruno@wolff.to) Received: (qmail 4062 invoked by uid 500); 11 Feb 2002 14:36:51 -0000 Date: Mon, 11 Feb 2002 08:36:51 -0600 From: Bruno Wolff III To: "Hunter, Ray" Cc: pgsql-sql@postgresql.org Subject: Re: Sequences Message-ID: <20020211143651.GA4020@wolff.to> Mail-Followup-To: "Hunter, Ray" , pgsql-sql@postgresql.org References: <59358A738F45D51186A30008C74CE250E81373@slc-exc1.ctron.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <59358A738F45D51186A30008C74CE250E81373@slc-exc1.ctron.com> User-Agent: Mutt/1.3.25i X-Archive-Number: 200202/107 X-Sequence-Number: 6535 On Mon, Feb 11, 2002 at 08:43:23AM -0500, "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? > > I would like to take the current value of the sequence and use it for a > value in an insert statement. > > > Example: > > insert into users ( "user_id", "user_fname", "user_lname", > "user_email" ) > values ( 'current sequence', 'Ray', 'Hunter', > 'rhunter@enterasys.com' ); I think you want to use nextval in this context. currval is used when you have already gotten a new sequence number and want to use it in several inserts in the same transaction. If you make user_id a serial type, then its default value will be nextval and you could use: insert into users ( "user_fname", "user_lname", "user_email" ) values ('Ray', 'Hunter', 'rhunter@enterasys.com' ); to add a row.