Context
Schema setup
create table users( id serial primary key );
Query 1
with t1 as (
insert into users default values
returning id
), t2 as (
insert into users default values
returning id
)
select id from t1;
Expectations
1
Result
1
Query 2
with t1 as (
insert into users default values
returning id
), t2 as (
insert into users default values
returning id
)
select id from t2;
Expectations
2
Result
1
Query 3
with t1 as (
insert into users default values
returning id
), t2 as (
insert into users default values
returning id
)
select id from t1
union all
select id from t2;
Expectations (taking in account results of Query 2)
1
1
Result
1
2
Question
What's wrong with my expectations and how to get the expected value from Query 2?