create table test_t(id int8); insert into test_t values (1); insert into test_t values (2); insert into test_t values (3); with aa as (update test_t set id=2 where id<3 returning id) select count(*) from aa;