0

When doing a Postgres full text search, is it possible to return the top 10 relevance-ranked rows (using LIMIT), but also get the total number of rows found?

I'd like to implement a Google-like message in my search results: "Showing rows 1 to 10 of 1000 results"

1 Answer 1

2

You can use window functions for that:

SELECT
  *,
  COUNT(*) OVER ()
FROM table
LIMIT 10
Sign up to request clarification or add additional context in comments.

2 Comments

Wow. That really works. I wonder about performance? Any insight?
@ccleve the same as SELECT COUNT(*) FROM table

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.