Received: from trade-india.com (mail.trade-india.com [130.94.20.28] (may be forged)) by postgresql.org (8.11.3/8.11.4) with SMTP id g1BFG5E73810 for ; Mon, 11 Feb 2002 10:16:06 -0500 (EST) (envelope-from mallah@trade-india.com) Received: (qmail 9725 invoked from network); 11 Feb 2002 15:19:12 -0000 Received: from ptil-235-129-del.primus-india.net (HELO trade-india.com) (203.196.129.235) by 130.94.22.209 with SMTP; 11 Feb 2002 15:19:12 -0000 Message-ID: <3C67E0F5.1E213068@trade-india.com> Date: Mon, 11 Feb 2002 20:49:17 +0530 From: mallah@trade-india.com X-Mailer: Mozilla 4.76 [en] (X11; U; Linux 2.4.2-2 i686) X-Accept-Language: en MIME-Version: 1.0 To: "Hunter, Ray" CC: pgsql-sql@postgresql.org Subject: Re: Sequences References: <59358A738F45D51186A30008C74CE250E81373@slc-exc1.ctron.com> Content-Type: multipart/alternative; boundary="------------9304687C891E90489C80E672" X-Archive-Number: 200202/110 X-Sequence-Number: 6538 --------------9304687C891E90489C80E672 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Further to Brunos' suggestion, if you require to use the same id for insertion in other tables (slaves) you should assign the value to a variable and use that value for inserting in other referencing tables eg $id = $dbh -> selectrow_array("select nextval('seq_name')"); (# perl specific) insert into users ( "user_id", "user_fname", "user_lname", "user_email" ) values ( $id , 'Ray', 'Hunter', 'rhunter@enterasys.com' ); insert into user_details ( "user_id", ..... other details .... ) values ( $id , .... other details .... ); "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' ); > > Thanks, > > Ray Hunter > Firmware Engineer > > ENTERASYS NETWORKS > > Phone: 801 887-9888 > Fax: 801 972-5789 > Email: rhunter@enterasys.com > www: www.enterasys.com --------------9304687C891E90489C80E672 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit Further to Brunos' suggestion,

if you require to use the  same id for insertion in other tables (slaves) you should
assign the value to a variable and use that value for inserting
in other referencing tables eg

 $id = $dbh -> selectrow_array("select nextval('seq_name')");  (# perl specific)

 insert into users ( "user_id", "user_fname", "user_lname", "user_email" )
        values ( $id , 'Ray', 'Hunter', 'rhunter@enterasys.com' );

 insert into user_details ( "user_id",  ..... other details ....  )
         values ( $id ,  .... other details .... );
 
 
 
 
 

"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' );

Thanks,

Ray Hunter
Firmware Engineer

ENTERASYS NETWORKS

Phone:          801 887-9888
Fax:            801 972-5789
Email:          rhunter@enterasys.com
www:            www.enterasys.com

--------------9304687C891E90489C80E672--