Fixed generated sql for postgres substring function