CREATE OR REPLACE VIEW config AS SELECT COALESCE (c.id*2-1, b.id*2) AS unique_id, c.id as recipient_id, b.id as domain_id, c.name, b.domain, COALESCE (c.name, '') || '@' || b.domain AS mail_address, COALESCE (c.check_virus, b.check_virus, a.check_virus) AS check_virus, COALESCE (c.check_spam, b.check_spam, a.check_spam) AS check_spam, COALESCE (c.check_banned, b.check_banned, a.check_banned) AS check_banned, COALESCE (c.check_header, b.check_header, a.check_header) AS check_header, COALESCE (c.deliver_virus, b.deliver_virus, a.deliver_virus) AS deliver_virus, COALESCE (c.deliver_spam, b.deliver_spam, a.deliver_spam) AS deliver_spam, COALESCE (c.deliver_banned, b.deliver_banned, a.deliver_banned) AS deliver_banned, COALESCE (c.deliver_header, b.deliver_header, a.deliver_header) AS deliver_header, COALESCE (c.addrext_virus, b.addrext_virus, a.addrext_virus) AS addrext_virus, COALESCE (c.addrext_spam, b.addrext_spam, a.addrext_spam) AS addrext_spam, COALESCE (c.addrext_banned, b.addrext_banned, a.addrext_banned) AS addrext_banned, COALESCE (c.addrext_header, b.addrext_header, a.addrext_header) AS addrext_header, COALESCE (c.quar_virus, b.quar_virus, a.quar_virus) AS quar_virus, COALESCE (c.quar_spam, b.quar_spam, a.quar_spam) AS quar_spam, COALESCE (c.quar_banned, b.quar_banned, a.quar_banned) AS quar_banned, COALESCE (c.quar_header, b.quar_header, a.quar_header) AS quar_header, COALESCE (c.warn_virus, b.warn_virus, a.warn_virus) AS warn_virus, COALESCE (c.warn_banned, b.warn_banned, a.warn_banned) AS warn_banned, COALESCE (c.warn_header, b.warn_header, a.warn_header) AS warn_header, COALESCE (c.adm_newvirus, b.adm_newvirus, a.adm_newvirus) AS adm_newvirus, COALESCE (c.adm_virus, b.adm_virus, a.adm_virus) AS adm_virus, COALESCE (c.adm_spam, b.adm_spam, a.adm_spam) AS adm_spam, COALESCE (c.adm_banned, b.adm_banned, a.adm_banned) AS adm_banned, COALESCE (c.adm_header, b.adm_header, a.adm_header) AS adm_header, COALESCE (c.required_hits, b.required_hits, a.required_hits) AS required_hits, COALESCE (c.rewrite_subject, b.rewrite_subject, a.rewrite_subject) AS rewrite_subject, COALESCE (c.size_limit, b.size_limit, a.size_limit) AS size_limit FROM defaults a CROSS JOIN domain_with_dfl b LEFT JOIN recipient_with_catchall c ON b.domain = c.domain;