我正在将一些information_schema的查询转换为系统目录查询,但字符最大长度的结果不同。
SELECT column_name,
data_type ,
character_maximum_length AS "maxlen"
FROM information_schema.columns
WHERE table_name = 'x'
返回我期望的结果,例如:
city character varying 255
company character varying 1000
等价目录查询
SELECT attname,
atttypid::regtype AS datatype,
NULLIF(atttypmod, -1) AS maxlen
FROM pg_attribute
WHERE CAST(attrelid::regclass AS varchar) = 'x'
AND attnum > 0
AND NOT attisdropped
看起来返回每个长度+4:
city character varying 259
company character varying 1004
为什么会有这个差异?总是从结果中减去4安全吗?