Constraint for multiple foreign key yet it's mutually exclusive (PostgreSQL)
As it sounds, you cannot solve this with one constraint, but nothing prevents you from defining more of them.  I believe something like this should work:

CREATE TABLE due (
    ...,
    d_invoice_id REFERENCES invoice (i_id),
    d_loan_id REFERENCES loan (l_id),
    ...,
    CHECK (   (d_invoice_id IS NULL AND d_loan_id IS NOT NULL) 
           OR (d_invoice_id IS NOT NULL AND d_loan_id IS NULL))
);


A column that has a foreign key defined on does not have to be NOT NULL, unlike the column it references.  Apart from that, you may define checks of arbitrary complexity - it is advisable to keep complexity at its necessary minimum, though.