pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas G. Lockhart <lockhart@alumni.caltech.edu>
To: hoelc@pd.jaring.my
Cc: pgsql-general@hub.org
Subject: Re: [INTERFACES] the last row in a table
Date: Tue, 09 Mar 1999 15:20:14 +0000
Message-ID: <36E53C2E.C2E59616@alumni.caltech.edu> (raw)
References: <36E163D7.CD95C55A@pd.jaring.my>
	<87emn1fwsq.fsf@tolikus.hq.aaanet.ru>
	<36E50F4A.CB527B78@pd.jaring.my>

> 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



view thread (8+ messages)  latest in thread

Message-ID: <36E53C2E.C2E59616@alumni.caltech.edu>
Permalink:  ../36E53C2E.C2E59616@alumni.caltech.edu/
Also on:    postgresql.org/message-id/36E53C2E.C2E59616@alumni.caltech.edu

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: lockhart@alumni.caltech.edu, hoelc@pd.jaring.my, pgsql-general@hub.org
  Subject: Re: [INTERFACES] the last row in a table
  In-Reply-To: <36E53C2E.C2E59616@alumni.caltech.edu>

* 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