postgresql - 在 Postgresql 中使用 varchar 而不是 varchar(n)

标签 postgresql text varchar

我正在设计一个数据库,因为我还不熟悉我想知道的以下数据类型:

如果我不关心字符向量的长度,使用 VARCHAR 是否合适? (即使字符串预计会很短?)

直到现在,当我需要存储非常长的字符串时,我一直在使用 TEXT (VARCHAR) 但阅读文档并提出问题我听说如果提供了最大长度并且存储的字符串的长度小于它,PostgreSQL 不会存储额外的字节。 我想最大长度是在远程设备无法承受大内存空间的情况下使用的。

有人能同意或解释一下吗?

最佳答案

来自文档:

There is no performance difference among these three types, apart from increased storage space when using the blank-padded type, and a few extra CPU cycles to check the length when storing into a length-constrained column. While character(n) has performance advantages in some other database systems, there is no such advantage in PostgreSQL; in fact character(n) is usually the slowest of the three because of its additional storage costs. In most situations text or character varying should be used instead.

关于postgresql - 在 Postgresql 中使用 varchar 而不是 varchar(n),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16525701/

相关文章:

json - 如何将 hylang s-表达式序列化为 PostgreSQL json/json-b?

macos - 将 isw*() ctype 函数引入 Mac OS X

java - JOptionPane 输出文本副本

text - 为什么 HTML5 Canvas 的 "width"对象中的 "actualBoundingBoxLeft + actualBoundingBoxRight"和 "TextMetrics"之间存在差异?

mysql - varchar(20) 和 varchar(50) 是一样的吗?

Postgresql:在 set-returning plpgsql 函数中选择数组的问题

java - JPA - INSERT 后的 PK 属性问题

python - MySQL VarChar 255 及以上

java - 如何在Java中的同一个jLabel中显示不同的行

SQL - 从 '1' s 的位置查找二进制表示