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.
| 引擎 | 類型 | 儲存 | 備註 |
|---|---|---|---|
| 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.
- SQL Server's TEXT is a dead end: excluded from most string functions and dependent on READTEXT/UPDATETEXT; VARCHAR(MAX) replaced it in 2005.
- 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.
- PostgreSQL's TEXT has no length limit: enforce one with VARCHAR(n) or a CHECK constraint when the schema should.
- Oracle's CLOBs live out-of-line: small LOBs cost extra I/O versus VARCHAR2, and comparisons need DBMS_LOB or explicit casts.
- 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.
Related on SQLly
- SQL data type comparison and converter Free tool
- CHAR versus VARCHAR semantics in SQL Server, PostgreSQL, MySQL, SQLite and Oracle Dialect comparison
- Column types for UUIDs and GUIDs in SQL Server, PostgreSQL, MySQL, SQLite and Oracle Dialect comparison
- Implicit casts in comparisons Dialect comparison
- Truncate a date to day, month or year in SQL Server, PostgreSQL, MySQL, SQLite and Oracle Dialect comparison
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.