ccleve
ccleve

Reputation: 15809

Get total hit count with Postgres full text search

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"

Upvotes: 0

Views: 481

Answers (1)

Hauleth
Hauleth

Reputation: 23586

You can use window functions for that:

SELECT
  *,
  COUNT(*) OVER ()
FROM table
LIMIT 10

Upvotes: 2

Related Questions