postgresql upsert中excluded可以理解为insert语句中的values的值
测似乎如下:
原来表中fracs的login_cnt等于2
mydb=# select * from user_logins;
user_name | login_cnt | last_login_time
-----------+-----------+---------------------
matiler | 1 |
francs | ** 2** | 2023-09-12 10:42:40
(2 rows)
mydb=# insert into user_logins values ('matiler',1),('francs',**3**) on conflict(user_name) do update set login_cnt=user_logins.login_cnt+excluded.login_cnt,last_login_time=now(); 插入值为3,若冲突则插入2+3
INSERT 0 2
^
mydb=# select * from user_logins;
user_name | login_cnt | last_login_time
-----------+-----------+---------------------
matiler | 2 | 2023-09-12 10:46:51
francs | ** 5 **| 2023-09-12 10:46:51
(2 rows)