SQL: CHAR pads, VARCHAR does not, TEXT has no limit

CHAR(n) stores exactly n characters and pads with spaces, which then come back in comparisons and concatenations. VARCHAR(n) and TEXT store what you gave them.

Code
CREATE TABLE t (a CHAR(10), b VARCHAR(10), c TEXT);
INSERT INTO t VALUES ('ab', 'ab', 'ab');

SELECT LENGTH(a), LENGTH(b), LENGTH(c) FROM t;
SELECT '[' || a || ']', '[' || b || ']' FROM t;
Output
length | length | length
     2 |      2 |      2      <- PostgreSQL strips trailing blanks in LENGTH

[ab        ] | [ab]           <- but concatenation keeps the padding

-- In PostgreSQL there is no performance difference between VARCHAR(n) and
-- TEXT; the length is a constraint, not a storage optimisation. In MySQL
-- the distinction matters more, especially for index prefix lengths.
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-25