Received: from golem.jpl.nasa.gov (IDENT:root@hectic-2.jpl.nasa.gov [128.149.68.204]) by hub.org (8.9.2/8.9.1) with ESMTP id KAA50495 for ; Tue, 9 Mar 1999 10:20:28 -0500 (EST) (envelope-from lockhart@alumni.caltech.edu) Received: from alumni.caltech.edu (localhost [127.0.0.1]) by golem.jpl.nasa.gov (8.8.5/8.8.5) with ESMTP id PAA10157; Tue, 9 Mar 1999 15:20:14 GMT Sender: tgl@mythos.jpl.nasa.gov Message-ID: <36E53C2E.C2E59616@alumni.caltech.edu> Date: Tue, 09 Mar 1999 15:20:14 +0000 From: "Thomas G. Lockhart" Organization: Caltech/JPL X-Mailer: Mozilla 4.07 [en] (X11; I; Linux 2.0.36 i686) MIME-Version: 1.0 To: hoelc@pd.jaring.my CC: pgsql-general@hub.org Subject: Re: [INTERFACES] the last row in a table References: <36E163D7.CD95C55A@pd.jaring.my> <87emn1fwsq.fsf@tolikus.hq.aaanet.ru> <36E50F4A.CB527B78@pd.jaring.my> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit > I am developing a database with PostgreSQL in Linux, and using ecpg to > write the C program to communicate with the database. > One of my application need to get the data from the last row in a > table. Is there any function or command that can tract which is the > last row of data in a table? SQL is a set-oriented language. One should probably not assign any significance to a storage order of rows. It *is* possible to order the results of a query, and then your first/last qualities do have meaning. I would suggest ordering your query (perhaps on a "row update time" if by "the last row" you mean "the more recently entered row") using the "DESC" qualifier in the ORDER BY clause, then use a cursor to pick up the first row returned. Good luck. - Tom