‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Sunday, May 19, 2019 4:44 PM, John Fawcett via dovecot <dovecot@dovecot.org> wrote:
I don't have PostgresSql, would you be able to verify if this syntax would work: INSERT INTO last_logins (last_login,username,domain) VALUES (1558273000,'user@domain.tld','domain.tld') ON CONFLICT (username) UPDATE SET last_login=1558273000,domain='user@domain.tld' It's important to check that this updates only the single row for that user and it puts the right data in that row. If it doesn't work can you give the correct syntax?
So you nearly yes ;-) The only parameter missing was "DO" keyword before the "UPDATE". So the correct query would be:
INSERT INTO last_logins (last_login,username,domain) VALUES (1558273000,'user@domain.tld','domain.tld') ON CONFLICT (username) DO UPDATE SET last_login=1558273000,domain='domain.tld';
I also adapted the domain='domain.tld' at the end of the query, you had domain='user@domain.tld' but this is just a "content" detail which does not matter.
Hope that helps. Let me know if I can do any further testing.
Attached is a tentative patch. I've verified no regression for
mysql. There should be no regression for sqlite as the code path
is identical.
Are you able to test for pgsql? As mentioned by Akie it will
break for PostgresSql < 9.5 but probably it was not working
anyway due to duplicate keys. Whether this is a wider problem
depends on whether the insert code is being used for other
purposes too.
If you or someone can verify it works on PostgresSql >= 9.5, then the next step will be to make it conditional on the version.
John
John