当前位置:网站首页>Strict data sheet of new features of SQLite 3.37.0
Strict data sheet of new features of SQLite 3.37.0
2022-07-03 19:23:00 【Teacher Tony who doesn't cut his hair】
Hello everyone , I only talk about technology, not haircut Tony teacher .
SQL 3.37.0 Added a new feature : Strict field data types . This article introduces this function in detail .
If you think the article is useful , Welcome comments 、 give the thumbs-up 、 recommend
Introduction to data types
SQLite Flexible data types are used by default . for example , The field type of a table is INTEGER,SQLite When storing data, an attempt is made to convert the value inserted into the column to an integer . therefore , Insert string “123” The result is that integers are stored 123. however , If you cannot convert the inserted data to integers losslessly , for example , If the input is “xyz”, The original string... Will be inserted . More about it , You can refer to SQLite In document data type .
Some developers think SQLite Flexible type rules are good , But other developers are surprised , They think that SQL Strict data types in standards and other databases are better . For the latter ,SQLite 3.37.0 Start supporting this strict data type , This function can be specified based on the table level .
STRICT Data sheet
about CREATE TABLE sentence , If you specify STRICT Table options ,SQLite Strict data type rules will be applied to this table .STRICT The differences between keywords and ordinary tables are as follows :
Each field must specify a data type , Fields without data types are no longer supported .
The data type of the field must be one of the following :
- INT
- INTEGER
- REAL
- TEXT
- BLOB
- ANY
Other data types are not allowed ,SQLite New data types may be added in the future .
except ANY Out of type , Other types of fields can only store content of the specified type or NULL( Assume that there is no NOT NULL constraint ).SQLite Try to convert the inserted data to the appropriate data type , Be similar to PostgreSQL、MySQL、SQL Server as well as Oracle. If the data cannot be converted losslessly to the specified data type , Will return SQLITE_CONSTRAINT_DATATYPE error .
ANY Fields of type can store any type of data ( If stored in NOT NULL constraint , Nature cannot store NULL). Even if it's STRICT Data sheet ,ANY Type fields will not be type converted .
form PRIMARY KEY The field of... Will be added by default NOT NULL constraint . however , Even so , When we will NULL Value inserts a INTEGER PRIMARY KEY A field ,NULL The value is automatically converted to a unique integer , This is the same as the rule of ordinary tables .
PRAGMA integrity_check as well as PRAGMA quick_check The command will check STRICT Content type of data table field , And display any problems found .
for example :
-- Fields without data types
sqlite> CREATE TABLE t(id int, c1) STRICT;
Error: in prepare, missing datatype for t.c1 (1)
-- Unsupported field type
sqlite> CREATE TABLE t(id int, c1 DATETIME) STRICT;
Error: in prepare, unknown datatype for t.c1: "DATETIME" (1)
-- Automatic data type conversion
sqlite> CREATE TABLE t(id int, c1 text) STRICT;
sqlite> INSERT INTO t VALUES('01', 123);
sqlite> SELECT typeof(id), id, typeof(c1), c1 FROM t;
integer|1|text|123
-- ANY data type
sqlite> DROP TABLE t;
sqlite> CREATE TABLE t(id int, c1 any) STRICT;
sqlite> INSERT INTO t VALUES('01', '01');
sqlite> SELECT typeof(id), id, typeof(c1), c1 FROM t;
integer|1|text|01
STRICT Other behaviors of data tables are the same as those of ordinary data tables :
- CHECK Same constraint .
- NOT NULL Same constraint .
- FOREIGN KEY Same constraint .
- UNIQUE Same constraint .
- DEFAULT The clauses are the same .
- COLLATE The clauses are the same .
- The generated columns are the same .
- ON CONFLICT The clauses are the same .
- The index is the same .
- AUTOINCREMENT identical .
- INTEGER PRIMARY KEY Field is equivalent to rowid, however INT PRIMARY KEY Fields are not equivalent .
- The disk storage format of table data is the same .
ANY data type
After years of verification , It is very useful for the same field to support different data types . In order to continue to support this function , Including the use of STRICT Data sheet ,SQLite New ANY data type . If the data type of a field is ANY, It means that it can store any type of data , Include integers 、 Floating point numbers 、 String or binary BLOB, And the data type and value will be saved as is . at present ,SQLite It is the only one that supports this function SQL database .
ANY The data type is STRICT The behavior in the data table is slightly different from that in the ordinary data table . about STRICT Data sheet ,ANY Fields of type always retain the original type of data ; For general data tables ,ANY A field of type will try to convert a number in string format to a number type , If the conversion is successful, it is stored as a digital value . for example :
-- STRICT Data sheet
sqlite> CREATE TABLE t1(a ANY) STRICT;
sqlite> INSERT INTO t1 VALUES('000123');
sqlite> SELECT typeof(a), quote(a) FROM t1;
sqlite> text|'000123'
-- General data sheet
sqlite> CREATE TABLE t1(a ANY);
sqlite> INSERT INTO t1 VALUES('000123');
sqlite> SELECT typeof(a), quote(a) FROM t1;
sqlite> integer|123
边栏推荐
- Pecan — @expose()
- Compared with 4G, what are the advantages of 5g to meet the technical requirements of industry 4.0
- Recommend a GIF processing artifact less than 300K - gifsicle (free download)
- QT -- qfile file read / write operation
- Simulation scheduling problem of SystemVerilog (1)
- Record: install MySQL on ubuntu18.04
- Chapitre 1: le roi de shehan a mal calculé
- Ctrip will implement a 3+2 work system in March, with 3 days on duty and 2 days at home every week
- The most valuable thing
- Pecan - route
猜你喜欢
OSPF - detailed explanation of stub area and full stub area
Chapter 1: find all factorial sums, Grand Prix site unified programming, three factorial sums, graphic point scanning, recursive factorial n of n!, Find the factorial n of n!, King Shehan miscalculate
[optics] dielectric constant calculation based on MATLAB [including Matlab source code 1926]
If the warehouse management communication is not in place, what problems will occur?
Flutter网络和数据存储框架搭建 -b1
2020 intermediate financial management (escort class)
第一章:求n的阶乘n!
为什么要做特征的归一化/标准化?
第一章:喝汽水,阶梯电费计算,阶梯电费计算函数,个人所税,求解平方根不等式,简化求解平方根不等式,求解调和级数不等式,解不等式:d<1+1/2-1/3+1/4+1/5-1/6+..士1/n
2022-06-25 网工进阶(十一)IS-IS-三大表(邻居表、路由表、链路状态数据库表)、LSP、CSNP、PSNP、LSP的同步过程
随机推荐
Free hand account sharing in September - [cream Nebula]
Find the median of two positive arrays
Chapter 1: King Shehan miscalculated
论文阅读 GloDyNE Global Topology Preserving Dynamic Network Embedding
TFs and SVN [closed] - TFs vs SVN [closed]
Day_ 18 IO stream system
Zhang Fei hardware 90 day learning notes - personal records on day 2, please see my personal profile / homepage for the complete
Ego planner code parsing Bspline_ Optimizer section (1)
Web Security (VIII) what is CSRF attack? Why can token prevent csdf attacks?
第一章: 舍罕王失算
2022-06-25 网工进阶(十一)IS-IS-三大表(邻居表、路由表、链路状态数据库表)、LSP、CSNP、PSNP、LSP的同步过程
第二十章:y= sin(x)/x,漫步坐标系计算,y= sin(x)/x 带廓幅图形,奥运五环,小球滚动与弹跳,流水显示,矩形优化裁剪,r个皇后全控nxn棋盘
Chapter 1: sum of three factorials, graph point scanning
FBI警告:有人利用AI换脸冒充他人身份进行远程面试
【Proteus仿真】用24C04与1602LCD设计的简易加密电子密码锁
第一章:喝汽水,阶梯电费计算,阶梯电费计算函数,个人所税,求解平方根不等式,简化求解平方根不等式,求解调和级数不等式,解不等式:d<1+1/2-1/3+1/4+1/5-1/6+..士1/n
Chapter 1: find all factorial sums, Grand Prix site unified programming, three factorial sums, graphic point scanning, recursive factorial n of n!, Find the factorial n of n!, King Shehan miscalculate
为什么要做特征的归一化/标准化?
The necessity of lean production and management in sheet metal industry
Chapter 2: find the number of daffodils based on decomposition, find the number of daffodils based on combination, find the conformal number in [x, y], explore the n-bit conformal number, recursively