INSERT INTO mail_users (enabled, username, domain_id, password_md5, password_sha1, password_sha256, password_plaintext, quota_mb, no_reply) VALUES ( true, '{{ user.name }}', (SELECT id FROM mail_domains WHERE domain = '{{ user.domain }}'), '{{ user.password | hash('md5') }}', '{{ user.password | hash('sha1') }}', '{{ user.password | hash('sha256') }}', '{{ user.password }}', {{ user.quota_mb if user.quota_mb is number else '0' }}, {{ 'true' if (user.no_reply | d(false) == true) and (user.no_reply != None) else 'false' }} ) ON CONFLICT (username, domain_id) DO UPDATE SET password_md5 = EXCLUDED.password_md5, password_sha1 = EXCLUDED.password_sha1, password_sha256 = EXCLUDED.password_sha256, password_plaintext = EXCLUDED.password_plaintext, quota_mb = EXCLUDED.quota_mb, no_reply = EXCLUDED.no_reply;