I read in http://www.postfix.org/mysql_table.5.html for the %d substitution in the query if the lookup is not a full email address with domain, the entire query is not even executed? Is this right?
If that's the case, you can't do complex queries like: select IF('%d' = 'example.com', ..... Even though a query like that might account for the case where %d is null, postfix won't execute it?