pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: mallah@trade-india.com
To: Hunter, Ray <rhunter@enterasys.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Sequences
Date: Mon, 11 Feb 2002 20:49:17 +0530
Message-ID: <3C67E0F5.1E213068@trade-india.com> (raw)
References: <59358A738F45D51186A30008C74CE250E81373@slc-exc1.ctron.com>

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

view thread (19+ messages)  latest in thread

Message-ID: <3C67E0F5.1E213068@trade-india.com>
Permalink:  ../3C67E0F5.1E213068@trade-india.com/
Also on:    postgresql.org/message-id/3C67E0F5.1E213068@trade-india.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mallah@trade-india.com, rhunter@enterasys.com
  Subject: Re: Sequences
  In-Reply-To: <3C67E0F5.1E213068@trade-india.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox