pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard_D_Levine@raytheon.com
To: Scott Marlowe <smarlowe@g2switchworks.com>
Cc: lorid <lorid@dri.edu>
Cc: pgsql-sql@postgresql.org
Cc: pgsql-sql-owner@postgresql.org
Subject: Re: getting back autonumber just inserted
Date: Fri, 4 Feb 2005 09:11:32 -0500
Message-ID: <OF868C6DCE.09564F53-ON05256F9E.004DB74F@ftw.us.ray.com> (raw)

I don't work with M$ DBs, but saw that "autonumber" is an M$ concept.
Purely for my own edification, how do you get the most resent value of an
autonumber in M$?  I was helping someone out who was using M$ stuff and was
amazed that there was no currval function.

Thanks,

Rick


                                                                                                                                         
                      Scott Marlowe                                                                                                      
                      <smarlowe@g2switchw        To:       lorid <lorid@dri.edu>                                                         
                      orks.com>                  cc:       pgsql-sql@postgresql.org                                                      
                      Sent by:                   Subject:  Re: [SQL] getting back autonumber just inserted                               
                      pgsql-sql-owner@pos                                                                                                
                      tgresql.org                                                                                                        
                                                                                                                                         
                                                                                                                                         
                      02/03/2005 05:16 PM                                                                                                
                                                                                                                                         
                                                                                                                                         




On Thu, 2005-02-03 at 16:16, lorid wrote:
> I could have sworn I kept a copy of prior emails that discussed how to
> get back a value that was just inserted into a autonumber (or in
> postgresql case a sequence number)


If you know the name of the sequence the number came from you can use
currval():

insert into table1 (info) values ('abc');
select currval('table1seq');

Assuming table1seq is the name of the sequence here.

In 8.0 there's a function to do this (I'm not sure of the name, but a
quick search of the 8.0 docs should turn it up.)

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to majordomo@postgresql.org so that your
      message can get through to the mailing list cleanly






view thread (30+ messages)  latest in thread

Message-ID: <OF868C6DCE.09564F53-ON05256F9E.004DB74F@ftw.us.ray.com>
Permalink:  ../OF868C6DCE.09564F53-ON05256F9E.004DB74F@ftw.us.ray.com/
Also on:    postgresql.org/message-id/OF868C6DCE.09564F53-ON05256F9E.004DB74F@ftw.us.ray.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: Richard_D_Levine@raytheon.com, smarlowe@g2switchworks.com, lorid@dri.edu, pgsql-sql-owner@postgresql.org
  Subject: Re: getting back autonumber just inserted
  In-Reply-To: <OF868C6DCE.09564F53-ON05256F9E.004DB74F@ftw.us.ray.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