Ryszard Kurek <rychu(at)sky(dot)pl> writes:
> The slow version is:
> SELECT min(product_symbol) FROM products WHERE product_name > 'current_product';
Try
SELECT ... FROM products WHERE product_name > 'current_product' ORDER BY product_name LIMIT 1;
You will need to have an index on product_name to make this fast ---
without the index there will be a sort step.
The ideal solution to your problem is probably
SELECT ... FROM products ORDER BY product_name LIMIT 1 OFFSET n;
which avoids issues like what happens when there is more than one row
with the same product_name. However, 6.5.* is not bright enough to
use an index for this kind of query (it only considers an index if
there is a matching WHERE clause). 7.0 will be smarter.
regards, tom lane