On 3/31/06 10:01 AM, "Frank Wiles" <[EMAIL PROTECTED]> wrote:
> On Fri, 31 Mar 2006 14:47:37 +0200
> Issac Goldstand <[EMAIL PROTECTED]> wrote:
>
>> Granted, I use a few MySQL features for this; I'm not sure if LIMIT
>> exists in postgresql, and I'm fairly sure that the SQL_CALC_FOUND_ROWS
>> directive (which will return the total rows in a select statement
>> regardless of the LIMIT directives) doesn't...
>
> PostgreSQL has LIMIT... it's a SQL standard. And I don't really see
> why you would need SQL_CALC_FOUND_ROWS unless you where going to
> show the total number of pages. For simple Next/Previous paging
> you just keep going until you fall off the end.
>
> If you need to get a count you can just do a count() on a particular
> column without the LIMIT and get a total.
In postgres, a count(*) can be fairly time-consuming, so a quick-and-dirty
hack is to parse the output of the "EXPLAIN ..." query to get the estimated
number of rows, which is often just fine as an estimate. If the database is
vacuumed often or is basically query-only, these numbers will often be very
close or the same as the real thing.
Sean