select
        ev.email_validation_public_id
        , i.identity_public_id
        , e.address
        , ev.attempts
        , ev.code
        , ev.is_validated
        , ev.created_at
        , ev.expires_at
        , ev.revoked_at
from email_validation ev
join identity_email   ie using (identity_email_id)
join email            e  using (email_id)
join identity         i  using (identity_id)
where ((?1 is null) or (email_validation_public_id = ?1))
and   ((?2 is null) or (code = ?2));
