为什么 SqliteStudio 在其 Create Table 语句中显示 DATETIME 列
Why is SqliteStudio showing DATETIME column in its Create Table statement
我读到日期时间存储在 sqlite 中的文本、实数或整数中,但 sqlitestudio 将日期时间列显示为日期时间,就像在下面的 DDL 中它显示日期时间列:
CREATE TABLE tblWeights (
uid STRING,
weight DOUBLE,
dt DATETIME,
printed INTEGER,
dispdt DATETIME,
transid INTEGER
);
怎么回事?
你是如何创建那个 table 的?
我猜测应用程序只是显示创建 table(由用户输入)的 DDL,而不是从元数据重新构造它。
为了兼容性,您 可以 声明一个列类型 DATETIME
(among many others),它将被视为 NUMERIC
(这依次是 "flexible" 类型,最终将存储文本、实数、整数、空值或 Blob,具体取决于数据的外观)。
答案是因为这是在创建 table 或更改 table 和添加列时使用的内容。
你实际上可以有一个几乎任何类型的列(decalred),甚至像 mycolumn rumplestiltskin NOT NULL
这样的东西,这将是 recorded/stored(类型亲和力将是 NUMERIC)。 SQLite 所做的是应用一个算法,然后使用一些简单的规则来应用 INTEGER、TEXT、NUMERIC、REAL 或 BLOB 的类型亲和性:-
3.1. Determination Of Column Affinity The affinity of a column is determined by the declared type of the column, according to the
following rules in the order shown:
If the declared type contains the string "INT" then it is assigned
INTEGER affinity.
If the declared type of the column contains any of the strings "CHAR",
"CLOB", or "TEXT" then that column has TEXT affinity. Notice that the
type VARCHAR contains the string "CHAR" and is thus assigned TEXT
affinity.
If the declared type for a column contains the string "BLOB" or if no
type is specified then the column has affinity BLOB.
If the declared type for a column contains any of the strings "REAL",
"FLOA", or "DOUB" then the column has REAL affinity.
Otherwise, the affinity is NUMERIC.
Note that the order of the rules for determining column affinity is
important. A column whose declared type is "CHARINT" will match both
rules 1 and 2 but the first rule takes precedence and so the column
affinity will be INTEGER.
Datatypes In SQLite Version 3
但是,另外,作为 rowid 或 rowid 本身的别名的列除外(必须具有唯一的 INTEGER) ,您可以在任何类型的列中存储任何类型的值。根据之前给出的 link,数据的存储方式(存储 Class)存在细微差别。
我读到日期时间存储在 sqlite 中的文本、实数或整数中,但 sqlitestudio 将日期时间列显示为日期时间,就像在下面的 DDL 中它显示日期时间列:
CREATE TABLE tblWeights (
uid STRING,
weight DOUBLE,
dt DATETIME,
printed INTEGER,
dispdt DATETIME,
transid INTEGER
);
怎么回事?
你是如何创建那个 table 的?
我猜测应用程序只是显示创建 table(由用户输入)的 DDL,而不是从元数据重新构造它。
为了兼容性,您 可以 声明一个列类型 DATETIME
(among many others),它将被视为 NUMERIC
(这依次是 "flexible" 类型,最终将存储文本、实数、整数、空值或 Blob,具体取决于数据的外观)。
答案是因为这是在创建 table 或更改 table 和添加列时使用的内容。
你实际上可以有一个几乎任何类型的列(decalred),甚至像 mycolumn rumplestiltskin NOT NULL
这样的东西,这将是 recorded/stored(类型亲和力将是 NUMERIC)。 SQLite 所做的是应用一个算法,然后使用一些简单的规则来应用 INTEGER、TEXT、NUMERIC、REAL 或 BLOB 的类型亲和性:-
3.1. Determination Of Column Affinity The affinity of a column is determined by the declared type of the column, according to the following rules in the order shown:
If the declared type contains the string "INT" then it is assigned INTEGER affinity.
If the declared type of the column contains any of the strings "CHAR", "CLOB", or "TEXT" then that column has TEXT affinity. Notice that the type VARCHAR contains the string "CHAR" and is thus assigned TEXT affinity.
If the declared type for a column contains the string "BLOB" or if no type is specified then the column has affinity BLOB.
If the declared type for a column contains any of the strings "REAL", "FLOA", or "DOUB" then the column has REAL affinity.
Otherwise, the affinity is NUMERIC.
Note that the order of the rules for determining column affinity is important. A column whose declared type is "CHARINT" will match both rules 1 and 2 but the first rule takes precedence and so the column affinity will be INTEGER. Datatypes In SQLite Version 3
但是,另外,作为 rowid 或 rowid 本身的别名的列除外(必须具有唯一的 INTEGER) ,您可以在任何类型的列中存储任何类型的值。根据之前给出的 link,数据的存储方式(存储 Class)存在细微差别。