Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

What is character varying data type?

The CHARACTER VARYING data type stores a string of letters, digits, and symbols of varying length, where m is the maximum size of the column (in bytes) and r is the minimum number of bytes reserved for that column.

What is maximum length of character varying Postgres?

The maximum limit of size character using character varying data type in PostgreSQL is 10485760. The below example shows that the size of the character using character varying data type in PostgreSQL is 10485760.

What is VARCHAR 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 default size of character varying in PostgreSQL?

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.


VARCHAR is an alias for CHARACTER VARYING, so no difference, see documentation :)

The notations varchar(n) and char(n) are aliases for character varying(n) and character(n), respectively. character without length specifier is equivalent to character(1). If character varying is used without length specifier, the type accepts strings of any size. The latter is a PostgreSQL extension.


The PostgreSQL documentation on Character Types is a good reference for this. They are two different names for the same type.


The only difference is that CHARACTER VARYING is more human friendly than VARCHAR


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. VARCHAR is a shorter alias which all modern databases also support. I prefer VARCHAR because it's shorter and because the longer name feels pedantic. However, postgres tools like pg_dump and \d will output character varying.


Both are the same thing but many of the databases are not providing the varying char mainly postgreSQL is providing. So for the multi database like Oracle Postgre and DB2 it is good to use the Varchar