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

DatabasePostgresqlVarcharVarying

Database Problem Overview


John uses CHARACTER VARYING in the places where I use VARCHAR. I am a beginner, while he is an expert. This suggests me that there is something which I do not know.

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

Database Solutions


Solution 1 - Database

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.

Solution 2 - Database

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

Solution 3 - Database

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.

Solution 4 - Database

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

Solution 5 - Database

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLéo Léopold Hertz 준영View Question on Stackoverflow
Solution 1 - DatabaseCharles MaView Answer on Stackoverflow
Solution 2 - DatabaseGreg HewgillView Answer on Stackoverflow
Solution 3 - DatabaseGordon HopperView Answer on Stackoverflow
Solution 4 - DatabaseinorView Answer on Stackoverflow
Solution 5 - DatabaseDaya ShankerView Answer on Stackoverflow