How to find offset/index base on id with order? How to find offset/index base on id with order?  

SELECT p.* 
FROM product p
WHERE p.id = $1
ORDER BY p.id desc NULLS LAST


id:1 return 0

id |
1  |
2  |
3  |
If you mean the number of rows with a smaller id value:

SELECT count(*) FROM product WHERE id &lt; $1;