Why is the value - despite of using GREATEST() - still out of range?
If your posts column is BIGINT UNSIGNED then unsigned values have to be 0 or more, so -1 is out of range.

MariaDB [test]&gt; desc tbl1;
+-------+---------------------+------+-----+---------+-------+
| Field | Type                | Null | Key | Default | Extra |
+-------+---------------------+------+-----+---------+-------+
| id    | bigint(20) unsigned | YES  |     | NULL    |       |
+-------+---------------------+------+-----+---------+-------+
1 row in set (0.01 sec)

MariaDB [test]&gt; select id -1 from tbl1;
ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '(`test`.`tbl1`.`id` - 1)'