insert..update更新
最近更新时间: 2025-02-18 16:02:00
- 使用ON CONFLICT。
postgres=# \d+ t
Table "public.t"
Column | Type | Modifiers | Storage | Stats target | Description
--------+---------+-----------+----------+--------------+-------------
id | integer | | plain | |
nc | text | | extended | |
Indexes:
"t_id_udx" UNIQUE, btree (id)
Has OIDs: no
Distribute By SHARD(id)
Location Nodes: ALL DATANODES
postgres=# select * from t;
id | nc
----+------
1 | pgxz
(1 row)
postgres=# insert into t values(1,'pgxz') ON CONFLICT (id) DO UPDATE SET nc = 'TDSQL PG';
INSERT 0 1
postgres=# select * from t;
id | nc
----+-------
1 | TDSQL PG
(1 row)