insert ... returning where X
There's an awful lot to be said for keeping things simple: 

begin;

insert into table123 ( id, val, num ) values ( nextval('table123seq'), 2, 42 ); 
insert into table123 ( id, val, num ) values ( nextval('table123seq'), 3, 42 ); 
insert into table123 ( id, val, num ) values ( nextval('table123seq'), 4, 42 ); 

insert into table456 ( id, num, fkey_id ) 
   select next( 'table546seq' ), 333, id 
   from table123 
   where table213.num = 2 ; 

select * from table456 ; 
commit ; 


Alternatively, make your id columns auto-increment and forget all about them entirely. 

If that's not what you're after, then a plain-English description of the Problem you're trying to solve - not the difficulties with your current attempt at solving it - would be a good place to start.