Constraints’s check time depend on deferrable parameters. If the parameter is set immediate, check time of your query is before the transaction is commit. Also, query will check when you execute query. If the parameter is set deferred, query will check when the transaction is commit;
Deferrable initially immediate
Deferrable initially deferred