From wvdakker@wilsoft.nl Fri Dec 8 23:06:31 2000 Received: from thor.tht.net (thor.tht.net [209.47.145.4]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id eB8N6VZ19124 for ; Fri, 8 Dec 2000 18:06:31 -0500 (EST) (envelope-from wvdakker@wilsoft.nl) Received: from linux.wilsoft.nl (root@apollo-hrn0451.multiweb.net [195.114.253.199]) by thor.tht.net (8.9.3/8.9.3) with ESMTP id SAA16920 for ; Fri, 8 Dec 2000 18:28:04 GMT (envelope-from wvdakker@wilsoft.nl) Received: from pentium (pentium.wilsoft.nl [10.2.0.5]) by linux.wilsoft.nl (8.9.3/8.9.3) with ESMTP id XAA18133 for ; Fri, 8 Dec 2000 23:28:09 +0100 Message-ID: <004401c06166$66bf1090$0500020a@wilsoft.nl> From: "W. van den Akker" To: Subject: How to... Date: Fri, 8 Dec 2000 23:30:00 +0100 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0041_01C0616E.C864CD00" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Archive-Number: 200012/63 X-Sequence-Number: 394 This is a multi-part message in MIME format. ------=_NextPart_000_0041_01C0616E.C864CD00 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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? gr, Willem ------=_NextPart_000_0041_01C0616E.C864CD00 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi,
 
I'am wondering if it is possible to retrie= ve the=20 last added
record of a table?
I don't think there is a default SQl-query= to do=20 so. Is there
a PostgreSQL way?
 
gr,
 
Willem
------=_NextPart_000_0041_01C0616E.C864CD00-- From jburton@scw.org Fri Dec 8 23:36:26 2000 Received: from thor.tht.net (thor.tht.net [209.47.145.4]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id eB8NaQZ21742 for ; Fri, 8 Dec 2000 18:36:26 -0500 (EST) (envelope-from jburton@scw.org) Received: from olympus.scw.org (209-9-156-98.sdsl.cais.net [209.9.156.98]) by thor.tht.net (8.9.3/8.9.3) with ESMTP id TAA17584 for ; Fri, 8 Dec 2000 19:13:52 GMT (envelope-from jburton@scw.org) Received: from hades (eos.scw.org [209.9.156.112]) by olympus.scw.org (8.10.1/8.10.1) with ESMTP id eB8NCfg11600; Fri, 8 Dec 2000 18:12:41 -0500 From: "Joel Burton" Organization: Support Center of Washington To: "W. van den Akker" Date: Fri, 8 Dec 2000 18:12:28 -0500 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: How to... CC: pgsql-sql@postgresql.org Message-ID: <3A31248C.3734.177F009@localhost> In-reply-to: <004401c06166$66bf1090$0500020a@wilsoft.nl> X-mailer: Pegasus Mail for Win32 (v3.12c) X-Archive-Number: 200012/65 X-Sequence-Number: 396 > 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)