Re: select items, and max id

From: "Luis H(dot)" <pgsql-novice(at)geekhouse(dot)no-ip(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Re: select items, and max id
Date: 2003-08-29 02:46:26
Message-ID: 003e01c36dd7$bdee8eb0$0301a8c0@bigbertha
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Thanks for the info. I just realized I had thought out the logic of my web
app in the wrong way. I will now be working with the number of items in the
table. I know there is a count() query, and earlier someone asked for a
better solution (that doesn't need to cycle through the table). Tom Lane
mentioned pg_class.reltuples, but said it wasn't a completely accurate
measure. Any suggestions?

Thanks.

----- Original Message -----
From: "Bruno Wolff III" <bruno(at)wolff(dot)to>
To: "Luis H." <pgsql-novice(at)geekhouse(dot)no-ip(dot)com>
Cc: <pgsql-novice(at)postgresql(dot)org>
Sent: Thursday, August 28, 2003 10:36 PM
Subject: Re: [NOVICE] select items, and max id

> On Thu, Aug 28, 2003 at 22:11:49 -0400,
> "Luis H." <pgsql-novice(at)geekhouse(dot)no-ip(dot)com> wrote:
> > I have a table where each row has an id unique identifier (separate from
the one postgreql does automatically). I want to be able to do a certain
SELECT query returning various rows, and also be able to check what the
maximum id was among the rows in the result. Is it possible to do this all
in the same query? Right now I do it in a very dumb way -- I execute the
query to get all the data, and then I re-execute it as a subquery and pull
out the max(id).
>
> Yes and no. You won't be able to return rows and the max id of the rows
> without effectively doing the query twice. However, you could order the
> output rows by the id and check the first (or last depending on sort
> direction) row to get the value you want.
>

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Bruno Wolff III 2003-08-29 02:57:07 Re: select items, and max id
Previous Message Cath Lawrence 2003-08-29 02:40:33 Boolean variables...