On 8/8/2012 3:03 PM, email builder wrote:
>
> 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.

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

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.

Brian

N.B. Test all suggested queries before putting into production,
including mine.

Reply via email to