Infinite scrolling with full text search in PostgreSQL
It seems correct to me, but I get this error: column "rank" does not exist.  It works if I replace rank with its expression in the WHERE clause. Will that impact performance?


Yes it will in as much as without that change the query does not work. So that's a positive effect, however rank will not be computed twice so there is no penalty for that.

Nevertheless the whole table needs to be scanned to generate the rank column before the order-by can be done, so efficiency is about the same as offset.


  A second question: how can I make keyset pagination work if I wanted to sort id ASC instead of id DESC


If it's a number type, use -id instead. else you'd have to expand the tuple comparison out into a big messy expression.