pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joel Burton <jburton@scw.org>
To: W. van den Akker <wvdakker@wilsoft.nl>
Cc: pgsql-sql@postgresql.org
Subject: Re: How to...
Date: Fri, 8 Dec 2000 18:12:28 -0500
Message-ID: <3A31248C.3734.177F009@localhost> (raw)
In-Reply-To: <004401c06166$66bf1090$0500020a@wilsoft.nl>

> Hi,
> 
> I'am wondering if it is possible to retrieve the last added
> record of a table?
> I don't think there is a default SQl-query to do so. Is there
> a PostgreSQL way?

What is it you want to do? If you want to find out what auto-
generated ID will be or was inserted, you can use a sequence 
function, like currval() on the sequence.

If you're just working in psql, you're shown the OID of insert as it 
happens. You could SELECT ... WHERE oid=xxxx to get the record 
back. Some interfaces (like DBD::Pg) provide functions to get this 
oid, so you could get the record that way.

If you don't mean the last insert period, but rather the last insert 
just to this table, you could add a TIMESTAMP column DEFAULT 
CURRENT_TIMESTAMP and just select the record w/the latest 
timestamp.

HTH,

--
Joel Burton, Director of Information Systems -*- jburton@scw.org
Support Center of Washington (www.scw.org)



view thread (2+ messages)

Message-ID: <3A31248C.3734.177F009@localhost>
Permalink:  ../3A31248C.3734.177F009@localhost/
Also on:    postgresql.org/message-id/3A31248C.3734.177F009@localhost

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: jburton@scw.org, wvdakker@wilsoft.nl
  Subject: Re: How to...
  In-Reply-To: <3A31248C.3734.177F009@localhost>
  References: <004401c06166$66bf1090$0500020a@wilsoft.nl> <3A31248C.3734.177F009@localhost>

* 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