Fixed select for postgres compatibility