prize18-8 Exercise 1: Characters Against Bytes in SQL ====================================================== Plan: length(value) gives code points; length(CAST(value AS BLOB)) gives bytes. ASCII passes both limits only when it is at most 5 long. Anything with multi-byte characters can pass the character limit and still fail the byte limit. ex1.py: import sqlite3 con = sqlite3.connect(":memory:") values = ["hello", "caf\u00e9 bar", "\u20ac\u20ac\u20ac\u20ac", "\U0001F600" * 3, "\u8a9e\u8a9e\u8a9e"] for v in values: chars, nbytes = con.execute("SELECT length(?), length(CAST(? AS BLOB))", (v, v)).fetchone() print(f"{ascii(v):28} chars={chars:2} bytes={nbytes:2} fits 5 chars: {chars <= 5!s:5} fits 5 bytes: {nbytes <= 5}") Real output (Python 3.14, bundled SQLite): 'hello' chars= 5 bytes= 5 fits 5 chars: True fits 5 bytes: True 'caf\xe9 bar' chars= 8 bytes= 9 fits 5 chars: False fits 5 bytes: False '\u20ac\u20ac\u20ac\u20ac' chars= 4 bytes=12 fits 5 chars: True fits 5 bytes: False '\U0001f600\U0001f600\U0001f600' chars= 3 bytes=12 fits 5 chars: True fits 5 bytes: False '\u8a9e\u8a9e\u8a9e' chars= 3 bytes= 9 fits 5 chars: True fits 5 bytes: False The euro, emoji and CJK strings pass a five-character limit but would fail a five-byte limit. If a product measures a column or an index key in bytes (check for yours), these values would be rejected or truncated even though they look short, and the problem appears only for non-ASCII data, which makes it easy to miss in testing with English sample text.