On Tue, Nov 17, 2020 at 02:33:38PM -0800, David Koski wrote:
> query =
> SELECT transport FROM (
> SELECT
> /* Transport table is highest rank */
> 1 as rank,
> REPLACE( transport, 'smtp:[68.66.148.91]', 'dovecot:') AS
> transport
> FROM
> view_transport
> WHERE
> tkey='%s'
> UNION ALL
> SELECT
> /* If not in transport table, check psudo transport table */
> 2 as rank,
> REPLACE( transport, 'smtp:[68.66.148.91]', 'dovecot:') AS
> transport
> FROM
> view_user_transport
> WHERE
> tkey='%s' AND relay_domain<'2'
> UNION ALL
> SELECT
> /* If nothing else, check if relay domain */
> 3 as rank,
> 'relay:' AS transport
> FROM
> virtual_domains
> WHERE
> name='%d' AND relay<>'0'
---------
> ) t ORDER BY rank
> LIMIT 1
As documented:
http://www.postfix.org/mysql_table.5.html
%d When the input key is an address of the form user@domain,
%d is replaced by the SQL quoted domain part of the
address. Otherwise, the query is suppressed and returns
no results.
when your query template uses '%d' the input key is required to be of
the form: '[email protected]', or else the query is skipped. Since
Postfix will issue queries for the bare domain, I don't see why you need
a '%d' there. Also, why 'UNION ALL' rather than 'UNION'? If there were
duplicate outputs, it would be best to return just one result.
--
Viktor.