From: | Ericson Smith <eric(at)did-it(dot)com> |
---|---|
To: | Postgresql General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: selecting the last record from a table |
Date: | 2002-11-19 19:32:52 |
Message-ID: | 1037734374.1500.1.camel@localhost.localdomain |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
You might want to get the sequence before you even do the insert...
SELECT nextval('my_sequence') as id
Then do the insert with the sequence and all other operations with the
"id". Sure you might have a few holes in the sequence if you abort an
insert, but this way you dont have to mess with OID's etc.
- Ericson
On Tue, 2002-11-19 at 14:07, Doug McNaught wrote:
> MT <mt(at)open2web(dot)com> writes:
>
> > I have a script that inserts a record into a table and increments the
> > unique field using nextval('my_sequence'). My problem is once I have
> > inserted the record, I'd like to select this same record and display
> > it so that the user knows he has actually inserted the record. I'm
> > wondering if there's a bit of sql to select the last record.
>
> SELECT * FROM mytable WHERE my_unique_field = currval('my_sequence');
>
> -Doug
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
From | Date | Subject | |
---|---|---|---|
Next Message | Dan Winslow | 2002-11-19 19:40:14 | Re: Update table with max occurance from another table |
Previous Message | Dan Winslow | 2002-11-19 19:30:46 | Re: Update table with max occurance from another table |