Postgresql的字符大小限制


Answers:


25

Postgres中有限字符类型(例如varchar(n))的最大大小为10485760。您可以通过以下方式进行检查:

create table test(id serial primary key, str varchar(10485761));

ERROR:  length for type varchar cannot exceed 10485760

该限制在源代码的以下片段(htup_details.h)中定义,但是在官方文档中未明确提及:

/*
 * MaxAttrSize is a somewhat arbitrary upper limit on the declared size of
 * data fields of char(n) and similar types.  It need not have anything
 * directly to do with the *actual* upper limit of varlena values, which
 * is currently 1Gb (see TOAST structures in postgres.h).  I've set it
 * at 10Mb which seems like a reasonable number --- tgl 8/6/00.
 */
#define MaxAttrSize     (10 * 1024 * 1024)

可变长度无限制类型(文本,varchar)的最大字符数未定义。所有字符串类型的字节数都有限制:

在任何情况下,可以存储的最长字符串约为1 GB。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.