>> I don't think mine is so confusing as you suggest if you take a second
> to understand it. Maybe if you read it with some whitespace: >> >> select >> if ('%d' = 'example-2.com', >> IFNULL( >> (select dest from aliases where addr = > '%u...@example.com'), >> (select addr from users where addr = '%u...@example.com') >> ), >> NULL) >> > > You almost never want to return a NULL result to Postfix using a SQL lookup. > This actually can mean an affirmative instead of a negative result. Thank you for the tip. > A better query might be: > (SELECT dest from aliases where addr = '%u...@example.com' AND '%d' > = > 'example.net') UNION > (SELECT addr from users where addr = '%u...@example.com' AND '%d' = > 'example.net') LIMIT 1 Funny, I think I posted almost the same query earlier on. :) And I like this version better because it seems more standardized SQL > Postfix expects an empty set (i.e. no rows returned) if it is to respond > negatively that a virtual alias does not exist. > Returning NULL does not equal no rows returned. Are you sure? I ask only because the query I posted above DOES work - it does reject invalid addresses normally (for the primary or secondary domain or other unrelated domains on the server). Maybe postfix even unintentionally gets a NULL back, tries to do something with it but fails and ultimately produces the same result?