SQL
5 min read
BEGINNER
Strings and Unicode
Quick AnswerCharacter types store text, including names in different languages. Unicode character counts and encoded byte counts are different concepts.
Core idea
Character types store text, including names in different languages. Unicode character counts and encoded byte counts are different concepts.
Minimal example
sql
SELECT length('سلام'), length(CAST('سلام' AS BLOB));Expected SQLite rows:
text
4 | 8How it works
PostgreSQL VARCHAR(n) limits character length, CHAR(n) is blank padded, and TEXT has no declared length limit. SQLite VARCHAR(n) does not enforce n. SQLite length returns Unicode code points for ordinary text without embedded NUL; it counts bytes for BLOB. A code point is not necessarily one visible grapheme. The fixture uses UTF-8.
Practical example
sql
SELECT id, label FROM type_labels ORDER BY id;Expected SQLite rows:
text
1 | سلام2 | NotebookCommon mistake and practice
Do not size text by assuming one byte per letter. Compare length of ASCII and Persian words and distinguish character count from byte count.