using varchar over varchar(n) with Postgresql
我正在设计一个数据库,因为我还不熟悉数据类型,我想知道以下内容:
如果我不关心字符向量的长度,是否适合使用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.