PostgreSQL pg_constraint 的 confupdtype / confdeltype 列使用未记录的字母 (space)。这是什么意思?
PostgreSQL pg_constraint's confupdtype / confdeltype columns using undocumented letter (space). What does it mean?
https://www.postgresql.org/docs/current/catalog-pg-constraint.html 的文档说:
Foreign key update action code: a = no action, r = restrict, c = cascade, n = set null, d = set default
并且根本没有提到 space。但它实际上使用了很多space(ascii码32):
ddevienne=> select '"'||confdeltype||'"', count(*) from pg_constraint group by confdeltype;
?column? | count
----------+-------
"a" | 242
"c" | 941
" " | 2210
"n" | 201
(4 rows)
Time: 3.968 ms
那么 space 是什么意思?为什么没有记录?
我使用的是 PostgreSQL v12,但在这方面,v12 和 v14 的文档是相同的。
更新(给出已接受的答案):
仅查看外键约束 (contype = 'f'
) 确实摆脱了 spaces。
ddevienne=> select '"'||confdeltype||'"', count(*) from pg_constraint where contype = 'f' group by confdeltype;
?column? | count
----------+-------
"a" | 242
"c" | 941
"n" | 201
(3 rows)
Time: 4.124 ms
ddevienne=> select '"'||confupdtype||'"', count(*) from pg_constraint where contype = 'f' group by confupdtype;
?column? | count
----------+-------
"a" | 1381
"c" | 2
"n" | 1
(3 rows)
Time: 3.361 ms
confdeltype
是NOT NULL
,所以对于外键约束以外的约束设置为空白
https://www.postgresql.org/docs/current/catalog-pg-constraint.html 的文档说:
Foreign key update action code: a = no action, r = restrict, c = cascade, n = set null, d = set default
并且根本没有提到 space。但它实际上使用了很多space(ascii码32):
ddevienne=> select '"'||confdeltype||'"', count(*) from pg_constraint group by confdeltype;
?column? | count
----------+-------
"a" | 242
"c" | 941
" " | 2210
"n" | 201
(4 rows)
Time: 3.968 ms
那么 space 是什么意思?为什么没有记录?
我使用的是 PostgreSQL v12,但在这方面,v12 和 v14 的文档是相同的。
更新(给出已接受的答案):
仅查看外键约束 (contype = 'f'
) 确实摆脱了 spaces。
ddevienne=> select '"'||confdeltype||'"', count(*) from pg_constraint where contype = 'f' group by confdeltype;
?column? | count
----------+-------
"a" | 242
"c" | 941
"n" | 201
(3 rows)
Time: 4.124 ms
ddevienne=> select '"'||confupdtype||'"', count(*) from pg_constraint where contype = 'f' group by confupdtype;
?column? | count
----------+-------
"a" | 1381
"c" | 2
"n" | 1
(3 rows)
Time: 3.361 ms
confdeltype
是NOT NULL
,所以对于外键约束以外的约束设置为空白