Control flow for SQL query with one database roundtrip?

Is it at all possible in Diesel to implement a query that has control flow, but which still operates in a single execution? For example, to implement something like:

-- if the following is true:
select exists (select id from source where field = :value)::bool;

-- do an insert
insert into target (a, b, c) select s.fk_id, :d, :e from source;

-- otherwise, issue an exception
raise Exception 'Condition is not satisfied';

In general, I would like to understand whether a control flow with multiple conditions, transactions and exceptions can also be implemented as a single Diesel query that runs in one database roundtrip, or is this a case where a stored procedure is necessary?

Thanks in advance!