Why is CAST insufficient for validating an entire integer field?
Casting text to INTEGER consumes its recognizable integer prefix. A converted value does not prove the entire input is a valid integer literal.
SQLite example and interpretation
Both 12ms and oops yield numeric results under a cast. Validate units and the complete field syntax during ingestion.
SELECT CAST('12ms' AS INTEGER),CAST('oops' AS INTEGER);Result [[12, 0]]
中文
为什么 CAST 不能验证导入字段是完整整数?
将文本转为 INTEGER 会消费可解析的整数前缀。不能从转换成功推断整串均符合整数格式。
SQLite 示例与适用条件
传感器报文 12ms 和字符串 oops 都能得到数值输出。入库时要先核对字段格式和计量单位。
SELECT CAST('12ms' AS INTEGER),CAST('oops' AS INTEGER);结果 [[12, 0]]