Reputation: 23824
The SQLite FAQ states that 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 type but I can not find anything similar in the SQLite documentation.
How to store a dynamically typed value in a SQLite database?
Upvotes: 1
Views: 243
Reputation: 74645
You don't need to specify a type constraint for a column.
Rather than something like:
CREATE TABLE example (x ANY)
You only need to use
CREATE TABLE example (x)
This results in a column with a type affinity of 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.
See Type Affinity on https://www.sqlite.org/datatype3.html
And, for bonus, the corresponding function for SYS.ANYDATA.getTypeName(X)
is typeof(X)
:
The typeof(X) function returns a string that indicates the datatype of the expression X: "null", "integer", "real", "text", or "blob".
From https://www.sqlite.org/lang_corefunc.html
Upvotes: 4