Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL character varying length limit

I am using character varying data type in PostgreSQL. I was not able to find this information in PostgreSQL manual. What is max limit of characters in character varying data type?

like image 758
Anton Avatar asked May 25 '10 13:05

Anton


People also ask

What is the limit of CHARACTER VARYING in PostgreSQL?

(This too is required by the SQL standard.) The notations varchar( n ) and char( n ) are aliases for character varying( n ) and character( n ) , respectively. If specified, the length must be greater than zero and cannot exceed 10485760. character without length specifier is equivalent to character(1) .

What is the difference between character and CHARACTER VARYING in PostgreSQL?

The short answer: there is no difference. The long answer: CHARACTER VARYING is the official type name from the ANSI SQL standard, which all compliant databases are required to support. (SQL compliance Feature ID E021-02.) VARCHAR is a shorter alias which all modern databases also support.

What is CHARACTER VARYING in PostgreSQL?

PostgreSQL supports a character data type called VARCHAR. This data type is used to store characters of limited length. It is represented as varchar(n) in PostgreSQL, where n represents the limit of the length of the characters. If n is not specified it defaults to varchar which has unlimited length.

What is Max length of VARCHAR in PostgreSQL?

The PostgreSQL Varchar data type is used to store characters of indefinite length based on the parameter n. It can store a string up to 65,535 bytes long.


2 Answers

Referring to the documentation, there is no explicit limit given for the varchar(n) type definition. But:

...
In any case, the longest possible character string that can be stored is about 1 GB. (The maximum value that will be allowed for n in the data type declaration is less than that. It wouldn't be very useful to change this because with multibyte character encodings the number of characters and bytes can be quite different anyway. If you desire to store long strings with no specific upper limit, use text or character varying without a length specifier, rather than making up an arbitrary length limit.)

Also note this:

Tip: 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.

like image 178
Frank Bollack Avatar answered Sep 20 '22 22:09

Frank Bollack


From documentation:

In any case, the longest possible character string that can be stored is about 1 GB.

like image 22
Quassnoi Avatar answered Sep 20 '22 22:09

Quassnoi