Need to be careful when trying to sort varchar field on PostgreSQL.
varchar
mydb=# create table t (id varchar); mydb=# insert into t values ('1'),('2'),('9'),('10'); INSERT 0 4 mydb=# select max(id) from t; max ----- 9 (1 row)