Both char(n) and varchar(n) can store up to n characters in length. If you try to store a longer string in the column that is either char(n) or varchar(n), PostgreSQL will issue an error.

However, one exception is that if the excess characters are all spaces, PostgreSQL will truncate the spaces to the maximum length and store the string.

If a string casts to a char(n) or varchar(n) explicitly, PostgresQL will truncate the string to n characters before inserting into the table.

The text data type can store a string with unlimited length.

If you do not specify the n integer for the varchar data type, it behaves like the text data type. The performance of the varchar (without n) and text are the same.

The only advantage of specifying the length specifier for the varchar data type is that PostgreSQL will check and issue an error if you try to insert a longer string into the varchar(n) column.

Unlike varchar, The character or char without the length specifier is the same as the character(1) or char(1).

Different from other database systems, in PostgreSQL, there is no performance difference among three character types. In most situation, you should use text or varchar, and varchar(n) if you want PostgreSQL to check for the length limit.

- - -
I still have 1700 characters left.

Interested in seeing what that post looks like in your favorite client. It isn't even HALF a full gab. Figured I'd go easy on people first.

Follow

@robcolbert I believe you meant a toot, you are on mastodon now.

But looked good here.

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.