Lists: | pgsql-general |
---|
From: | Victor Spång Arthursson <scooterbabe(at)home(dot)se> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Equivalent for mysql's FOUND_ROWS() |
Date: | 2004-05-11 08:51:34 |
Message-ID: | 67FF445C-A328-11D8-99EA-00039344A3C4@home.se |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
With mysql it's possible to add a parameter "SQL_CALC_FOUND_ROWS" to
the selectstatement and then after having made a query to the database
with a limit clause you can fire off a second query, "SELECT
found_rows() as numberofrows" to get the number of rows the query would
have returned without the LIMIT-clause…
I wonder, is there any way, exept splitting the query up and make
different calls to the database, to accomplish the same with postgresQL
as with mysql?
Sincerely
Victor
From: | Jan Wieck <JanWieck(at)Yahoo(dot)com> |
---|---|
To: | Victor Spång Arthursson <scooterbabe(at)home(dot)se> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Equivalent for mysql's FOUND_ROWS() |
Date: | 2004-05-21 12:05:06 |
Message-ID: | 40ADF072.2010509@Yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Victor Spång Arthursson wrote:
> With mysql it's possible to add a parameter "SQL_CALC_FOUND_ROWS" to
> the selectstatement and then after having made a query to the database
> with a limit clause you can fire off a second query, "SELECT
> found_rows() as numberofrows" to get the number of rows the query would
> have returned without the LIMIT-clause…
>
> I wonder, is there any way, exept splitting the query up and make
> different calls to the database, to accomplish the same with postgresQL
> as with mysql?
Don't use LIMIT.
Open a cursor for the select, fetch the number of rows you want, if the
FETCH returned that many, do a "MOVE FORWARD ALL IN <cursorname>". The
number of rows skipped by the MOVE will be PQcmdTuples(result), so the
rows you got from FETCH plus that number is the information you're
looking for.
Jan
>
> Sincerely
>
> Victor
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #