The problems was in here:
http://www.postfix.org/mysql_table.5.html

              %u     When the input key is an address of the form
                     u...@domain,  %u  is  replaced  by  the  SQL
                     quoted local part of  the  address.   Other-
                     wise,  %u  is  replaced by the entire search
                     string.  If  the  localpart  is  empty,  the
                     query  is suppressed and returns no results.

The solution is very dirty;

SELECT rcpt FROM aliases WHERE alias IN ('%s',(SELECT REPLACE('%s', '@%d',
CONCAT('@', alias_of)) FROM domains WHERE domain = '%d'))

I'd really like to find out WHY the query is suppressed when %u is used and
%u is empty....

Tino



-----Oorspronkelijk bericht-----
Van: [email protected]
[mailto:[email protected]] Namens Tino Donderwinkel
Verzonden: vrijdag 31 juli 2009 23:59
Aan: [email protected]
Onderwerp: mySQL Query not working

I have a virtual_alias map setup that uses this mySQL query;

SELECT rcpt FROM aliases WHERE alias = '%s' OR alias = (SELECT CONCAT('%u@',
alias_of) FROM domains WHERE domain = '%d')

Postmap -q @domain.com mysql:/etc/postfix/aliases gives me NO results.

If I change the query to:

SELECT rcpt FROM aliases WHERE alias = '%s'

Postmap -q @domain.com mysql:/etc/postfix/aliases gives me the expected
result; [email protected].

But this way I have 'disabled' my own quick and dirty implementation of
'alias' domains.
What's wrong in the second part of the query? (the query works in mysql;
there are no syntax errors)

Btw; the domains table is like this;

domain | alias_of 
domain.com
aliasdomain.com | domain.com

The (SELECT CONCAT('%u@', alias_of) FROM domains WHERE domain = '%d') part
of the query located the aliases for an 'aliased' domain. (So if an alias
for domain.com exists, this alias is also found in aliasdomain.com)

Any ideas what's messing things up?

Thanks,

Tino Donderwinkel

Reply via email to