如何在 SQLite 数据库中存储动态类型的值?

How to store a dynamically typed value in a SQLite database?

SQLite 常见问题解答指出 SQLite uses dynamic typing. But I can not find a description how to write a dynamically typed value into the database. From Oracle I know the SYS.ANYDATA 类型,但我在 SQLite 文档中找不到任何类似内容。

如何在 SQLite 数据库中存储动态类型的值?

您不需要为列指定类型约束。

而不是像这样的东西:

CREATE TABLE example (x ANY)

你只需要使用

CREATE TABLE example (x)

这导致列的类型关联为 NONE。

A column with affinity NONE does not prefer one storage class over another and no attempt is made to coerce data from one storage class into another.

参见 https://www.sqlite.org/datatype3.html

上的类型亲和性

还有,为了加分,SYS.ANYDATA.getTypeName(X)对应的函数是typeof(X):

The typeof(X) function returns a string that indicates the datatype of the expression X: "null", "integer", "real", "text", or "blob".

来自https://www.sqlite.org/lang_corefunc.html