0

VARCHAR(n) is a variable-length character string of size up to n, but Postgres allows the limit to be omitted, so that VARCHAR and TEXT both mean a variable-length character string with no size limit (or, well, presumably some large limit imposed by the implementation).

It has been said that there is no performance difference between the two e.g. in Postgres: Convert varchar to text

Is there are any difference at all? If not, why are they still considered two different types?

rwallace
  • 31,405
  • 40
  • 123
  • 242
  • 2
    You should always start at the docs [Character types](https://www.postgresql.org/docs/current/datatype-character.html): in particular *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; ...* – Adrian Klaver Jun 09 '23 at 23:28
  • 2
    Or for a more explicit statement from same link: *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.*. – Adrian Klaver Jun 09 '23 at 23:29
  • 1
    I believe they were different years ago (varchar was always inline, and text could be stored in the TOAST); but evolution made both types converge into exactly the same handling. So yeah: they are working exactly the same now. – Guillaume F. Jun 09 '23 at 23:34
  • Though they may still be treated very differently by your client-side library – Nick Barnes Jun 10 '23 at 07:55

0 Answers0