From: | Rod Kreisler <rod(at)23net(dot)net> |
---|---|
To: | Rory Campbell-Lange <mail(at)campbell-lange(dot)net> |
Cc: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: Return serial from insert |
Date: | 2002-11-08 16:23:20 |
Message-ID: | JNEGKNDJGBKLBDGPOPFOEEEADEAA.rod@23net.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
You misunderstand. I wrote "...get the nextval() from the sequence and use
that for the NEW INSERT..."
If you table definition is like:
create "myTable"
(
id serial primary key,
foo char(5),
bar numeric(10,2)
)
The sequence created would be "myTable_id_seq". To do what you want:
1) get the nextval -- (select nextval("myTable_id_seq"::text);)
2) name the image file using the value from nextval
3) insert the record using the value from nextval: (insert into "myTable"
(id,foo,bar) values (valueFromNextVal,'foob',5.4);)
2 & 3 are interchangeable
> -----Original Message-----
> From: Rory Campbell-Lange [mailto:mail(at)campbell-lange(dot)net]
> Sent: Friday, November 08, 2002 11:02 AM
> To: Rod Kreisler
> Cc: Rory Campbell-Lange; pgsql-novice(at)postgresql(dot)org
> Subject: Re: [NOVICE] Return serial from insert
>
>
> The problem is that I need to use the id for naming an image file.
> Consequently I need the id from the insert. You will note (from my
> original messgage) that I'm already using a SERIAL type field for the id
> column.
>
> On 08/11/02, Rod Kreisler (rod(at)23net(dot)net) wrote:
> > You should get the nextval() from the sequence and use that for the new
> > insert and all related inserts.
> >
> > > -----Original Message-----
> > > From: pgsql-novice-owner(at)postgresql(dot)org
> > > [mailto:pgsql-novice-owner(at)postgresql(dot)org]On Behalf Of Rory
> > > Campbell-Lange
> > > Sent: Friday, November 08, 2002 10:30 AM
> > > To: pgsql-novice(at)postgresql(dot)org
> > > Subject: [NOVICE] Return serial from insert
> > >
> > >
> > > I would like to return the autoincremented serial number
> resulting from
> > > a new insert into a table, ideally as a result from the insert
> > > statement.
>
> --
> Rory Campbell-Lange
> <rory(at)campbell-lange(dot)net>
> <www.campbell-lange.net>
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Nick Sayer | 2002-11-08 17:21:23 | Re: creating table with an encrypted filed |
Previous Message | Rory Campbell-Lange | 2002-11-08 16:02:07 | Re: Return serial from insert |