我正在设计一个数据库,因为我还不熟悉我想知道的以下数据类型:
如果我不关心字符向量的长度,使用 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/