From: Peter Eisentraut <peter_e@gmx.net>
To: Gerald Gutierrez <gml1@coldresist.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Getting row with id=max(id)
Date: Thu, 7 Jun 2001 19:31:34 +0200 (CEST)
Message-ID: <Pine.LNX.4.30.0106071929140.757-100000@peter.localdomain> (raw)
In-Reply-To: <5.1.0.14.0.20010607100000.02b8ae58@coldresist.com>
Gerald Gutierrez writes:
> SELECT * FROM mytable WHERE id=(SELECT MAX(id) FROM mytable);
>
> The subquery can take a /really/ long time on a table that is large. The query:
>
> SELECT * FROM mytable ORDER BY id DESC LIMIT 1;
>
> doesn't seem to help very much. What query is the fastest at getting this row?
One of these two. ;-)
The second is generally thought to be faster, at least if you use the
latest version of PostgreSQL.
> A related question is: is there a way to time a query in psql, like the
> client of MySQL does?
Not in a built-in way.
--
Peter Eisentraut peter_e@gmx.net http://funkturm.homeip.net/~peter
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: peter_e@gmx.net, gml1@coldresist.com
Subject: Re: Getting row with id=max(id)
In-Reply-To: <Pine.LNX.4.30.0106071929140.757-100000@peter.localdomain>
References: <5.1.0.14.0.20010607100000.02b8ae58@coldresist.com> <Pine.LNX.4.30.0106071929140.757-100000@peter.localdomain>
* 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