加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

SQLITE日期没有选中类型

发布时间:2020-12-12 23:42:51 所属栏目:百科 来源:网络整理
导读:我刚刚测试了sqlite并创建了一个表. $sqlite3 plop.dbsqlite CREATE TABLE t (d DATE);sqlite INSERT INTO t (d) VALUES ('Hello');sqlite PRAGMA table_info(t);0|a|DATE|0||0sqlite SELECT * FROM t;Hello 那么,当我尝试将CHAR(5)插入DATE时,为什么没有错
我刚刚测试了sqlite并创建了一个表.
$sqlite3 plop.db

sqlite> CREATE TABLE t (d DATE);

sqlite> INSERT INTO t (d) VALUES ('Hello');

sqlite> PRAGMA table_info(t);
0|a|DATE|0||0

sqlite> SELECT * FROM t;
Hello

那么,当我尝试将CHAR(5)插入DATE时,为什么没有错误?

来自Sqlite的 Frequently Asked Questions

SQLite lets me insert a string into a database column of type integer!

This is a feature,not a bug. SQLite uses dynamic typing. It does not
enforce data type constraints. Any data can be inserted into any
column. You can put arbitrary length strings into integer columns,
floating point numbers in boolean columns,or dates in character
columns. The datatype you assign to a column in the CREATE TABLE
command does not restrict what data can be put into that column. Every
column is able to hold an arbitrary length string. (There is one
exception: Columns of type INTEGER PRIMARY KEY may only hold a 64-bit
signed integer. An error will result if you try to put anything other
than an integer into an INTEGER PRIMARY KEY column.)

But SQLite does use the declared type of a column as a hint that you prefer values in that format. So,for example,if a column is of type INTEGER and you try to insert a string into that column,SQLite will attempt to convert the string into an integer. If it can,it inserts the integer instead. If not,it inserts the string. This feature is called type affinity.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读