Is a varchar unlimited in Postgresql?
Is a varchar unlimited in Postgresql? I read this text online and it was confusing:
"In PostgreSQL, the Varchar data type is used to keep the character of infinite length. And it can hold a string with a maximum length of 65,535 bytes."
Does that mean that in postgres, a varchar can only hold a maximum of 65,535 characters? Or can a varchar hold an unlimited amount of characters?
I need to be able to hold an unlimited amount of characters in the database table. There is a lot of incoming data that could get into the millions of characters per column.
Edit:
So based on replies, is looks like the 65,535 character limit is not true. What is the limit then? Someone said 1GB. Is that true? Is there a way to make a varchar truly unlimited?
Solution 1:
Quote from the manual
if character varying is used without length specifier, the type accepts strings of any size.
"Of any size" means up to 1GB as that is the maximum length of any column value.
In any case, the longest possible character string that can be stored is about 1 GB
Solution 2:
The limit for varchar
when you specify a length limit (type modifier) is 10485760:
SELECT 'x'::varchar(1000000000);
ERROR: length for type varchar cannot exceed 10485760
Without the type modifier, the size can be up to 1GB (just like text
).