everybody using mysql knows:
SELECT SQL_CALC_FOUND_ROWS ..... FROM table WHERE ... LIMIT 5, 10;
and right after run this :
SELECT FOUND_ROWS();
how do i do this in postrgesql? so far, i found only ways where i have to send the query twice…
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, there is not (at least not as of July 2007). I’m afraid you’ll have to resort to:
The isolation level needs to be
SERIALIZABLEto ensure that the query does not see concurrent updates between the SELECT statements.Another option you have, though, is to use a trigger to count rows as they’re
INSERTed orDELETEd. Suppose you have the following table:Then, perform the following to create a table called post_count that contains a running count of the number of rows in
posts:Note that this maintains a running count of all of the rows in
posts. To keep a running count of certain rows, you’ll have to tweak it: