// data type reference

TEXT and CLOB

The large-text options, from SQLite's everyday TEXT to Oracle's 128 TB CLOB.

Family
Texto
Missing in
SQL Server
Gotchas
5 listed

Engine by engine

PostgreSQL and SQLite treat TEXT as the plain string type; MySQL tiers it; SQL Server retired TEXT for VARCHAR(MAX); Oracle says CLOB.

TEXT / CLOB in SQL Server, PostgreSQL, MySQL, SQLite and Oracle: type name, storage and notes
Motor Tipo Armazenamento Notas
SQL Server no TEXT - use VARCHAR(MAX) Workaround up to 2 GB TEXT and NTEXT are deprecated since 2005 and slated for removal; new columns use VARCHAR(MAX) or NVARCHAR(MAX).
PostgreSQL TEXT up to 1 GB TEXT and VARCHAR share one implementation; VARCHAR(n) only adds a length check, and CHAR(n) adds padding.
MySQL TEXT / LONGTEXT 64 KB / 4 GB TINYTEXT 255 bytes, TEXT 64 KB, MEDIUMTEXT 16 MB, LONGTEXT 4 GB; plain TEXT takes no DEFAULT (expression defaults from 8.0.13).
SQLite TEXT up to 1 billion bytes Stored in the database encoding (UTF-8 or UTF-16); SQLITE_MAX_LENGTH caps a value at 1,000,000,000 bytes by default.
Oracle CLOB / NCLOB up to 128 TB LOB storage sits out-of-line; VARCHAR2 caps at 4000 bytes (32,767 with extended data types).

Gotchas

Where the engines disagree. These tend to surface as bugs during a migration or a port.

  1. SQL Server's TEXT is a dead end: excluded from most string functions and dependent on READTEXT/UPDATETEXT; VARCHAR(MAX) replaced it in 2005.
  2. MySQL's TEXT columns take no literal DEFAULT (only an expression default, from 8.0.13), and before 8.0.13 any query whose temporary table held a TEXT column went straight to disk.
  3. PostgreSQL's TEXT has no length limit: enforce one with VARCHAR(n) or a CHECK constraint when the schema should.
  4. Oracle's CLOBs live out-of-line: small LOBs cost extra I/O versus VARCHAR2, and comparisons need DBMS_LOB or explicit casts.
  5. In SQLite, CHAR(n), VARCHAR(n) and TEXT all get TEXT affinity and none enforces a length; a CHECK (length(col) <= n) is the only way to cap one.

Common questions

Is TEXT deprecated?

In SQL Server yes, in favor of VARCHAR(MAX). In MySQL and PostgreSQL TEXT is fully supported for large strings.

TEXT or VARCHAR for emails?

A limited VARCHAR, such as VARCHAR(320): it documents the limit and, in MySQL, can be fully indexed, while a TEXT column needs a prefix length to be indexed at all.

How big is a MySQL TEXT column?

Up to 65,535 bytes. MEDIUMTEXT reaches 16 MB and LONGTEXT 4 GB; the limit is in bytes, not characters.

// map types before you move data

Map a type to the other four engines

The free type converter maps a type from one engine to its closest equivalent in the others and says where storage, precision or behaviour differ. The desktop app does the same mapping while you edit.