sql fetch + pgsql changes