my $pinfo = $self->db->xhashref( select => [ 'n.id', 'p.hash' ], from => 'nodes n', inner_join => 'projects p', on => 'p.id = n.id', where => { 'n.uuid' => $uuid }, ); # Try and do this with an ORM! $dbw->xdo( insert_into => [ 'func_new_topic_status', qw/change_id id project_id tkind status rank def bill/, ], select => [ qv( $opts->{change_id} ), 'nextval("nodes")', qv( $opts->{id} ), 'ts.tkind', 'ts.status', 'ts.rank', 'ts.def', qv( $opts->{bill} // 1 ), ], from => 'topic_status ts', where => { 'ts.project_id' => $dup_pinfo->{id} }, order_by => [qw/ts.tkind ts.rank/] );