sql fixes for postgres