我有一个名为 attr 字段的 jsonb 类型,其中包含以下内容:
{
"pid": 1,
"name": "john",
"is_default": true
}
Run Code Online (Sandbox Code Playgroud)
如何将 is_default 更改为 false?
我试着跑到下面,但没有成功。
update attr set attr ->> 'is_default' = false where sales_type = 2
Run Code Online (Sandbox Code Playgroud) 我在 PostgreSQL 13 中有下表:
field type
----- ----
Seq bigserial
code varchar
Run Code Online (Sandbox Code Playgroud)
Seq
是主键(自增)
Code
是唯一键索引
Insert Into newtable (Code) Values ('001') On Conflict(Code) Do Nothing --> Seq value is 1
Insert Into newtable (Code) Values ('001') On Conflict(Code) Do Nothing
Insert Into newtable (Code) Values ('001') On Conflict(Code) Do Nothing
Insert Into newtable (Code) Values ('002') On Conflict(Code) Do Nothing --> Seq value is 4
Run Code Online (Sandbox Code Playgroud)
为什么是序列4?有什么方法可以仅在成功插入时增加价值?