postgresql 9.2中varchar(n)的最大长度是多少,最好使用varchar(n)或text? [英] what is the maximum length of varchar(n) in postgresql 9.2 and which is best to use varchar(n) or text?
问题描述
我正在使用PostgreSQL 9.2,我想使用varchar(n)存储一些长字符串,但是我不知道varchar(n)支持的最大字符长度。哪一种比较好用,所以请您提出建议?谢谢
Hi I am using postgresql 9.2 and I want to use varchar(n) to store some long string but I don't know the maximum length of character which varchar(n) supports. and which one is better to use so could you please suggest me? thanks
推荐答案
tl; dr:1 GB(每个字符(确实是:代码点)可能由1个或多个字节表示,具体取决于它们在unicode平面上的位置-假设是UTF-8编码的数据库)。现在,您应该始终对Postgresql中的任意长度字符数据使用 text
数据类型。
tl;dr: 1 GB (each character (really: codepoint) may be represented by 1 or more bytes, depending on where they are on a unicode plane - assuming a UTF-8 encoded database). You should always use text
datatype for arbitrary-length character data in Postgresql now.
说明:
varchar(n)
和 text
使用相同的后端存储类型( varlena
):具有32位长度计数器的可变长度字节数组。对于索引行为,文本
甚至可能具有一些性能优势。在Postgres中,最好使用 text
类型进行新开发;出于SQL标准支持原因,仍保留 varchar(n)
。注意: varchar()
(带有空括号)是 text
的Postgres专用别名。
Explanation:
varchar(n)
and text
use the same backend storage type (varlena
): a variable length byte array with a 32bit length counter. For indexing behavior text
may even have some performance benefits. It is considered a best practice in Postgres to use text
type for new development; varchar(n)
remains for SQL standard support reasons. NB: varchar()
(with empty brackets) is a Postgres-specific alias for text
.
另请参阅:
http://www.postgresql.org/about/
这篇关于postgresql 9.2中varchar(n)的最大长度是多少,最好使用varchar(n)或text?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!