last_login plugin with MySQL

Sven Hartge sven at svenhartge.de
Sat Oct 18 16:07:05 UTC 2014


Luigi Rosa <lists at luigirosa.com> wrote:

> I was expecting an UPDATE...WHERE but I got this:

> INSERT INTO mailbox (lastlogin,username) VALUES ('1413647370','username') ON
> DUPLICATE KEY UPDATE lastlogin='1413647370'

> This is not very useful if I want a `lastlogin` field of the `mailbox` table
> updated on every login.

This SQL query looks correct to me. It INSERTs a new row for a username
if one does not already exist but UPDATEs it if there is already such a
row.

This is the normal and advised way of doing this specific task in an
atomic way by using the "ON DUPLICATE" syntax of SQL.

Grüße,
Sven.

-- 
Sigmentation fault. Core dumped.



More information about the dovecot mailing list