当前位置:网站首页>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
边栏推荐
- Thinking about festivals
- Foundation of ActiveMQ
- 第一章:递归求n的阶乘n!
- Zhang Fei hardware 90 day learning notes - personal records on day 4, please see my personal profile / homepage for the complete
- Simulation scheduling problem of SystemVerilog (1)
- 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
- [new year job hopping season] test the technical summary of interviewers' favorite questions (with video tutorials and interview questions)
- Flume learning notes
- OSPF - detailed explanation of stub area and full stub area
- Record: pymysql is used in pycharm to connect to the database
猜你喜欢

Basic principle of LSM tree

Dart JSON编码器和解码器剖析
![[mathematical modeling] ship three degree of freedom MMG model based on MATLAB [including Matlab source code 1925]](/img/a9/d89ee2b88517eea6b3c38d72cf099f.jpg)
[mathematical modeling] ship three degree of freedom MMG model based on MATLAB [including Matlab source code 1925]

Flutter network and data storage framework construction-b1

2022-07-02 网工进阶(十五)路由策略-Route-Policy特性、策略路由(Policy-Based Routing)、MQC(模块化QoS命令行)

Record: pymysql is used in pycharm to connect to the database

Ctrip will implement a 3+2 work system in March, with 3 days on duty and 2 days at home every week

第一章:求同吗小数和s(d, n)

【数学建模】基于matlab船舶三自由度MMG模型【含Matlab源码 1925期】

【疾病识别】基于matlab GUI机器视觉肺癌检测系统【含Matlab源码 1922期】
随机推荐
Use unique_ PTR forward declaration? [repetition] - forward declaration with unique_ ptr? [duplicate]
[leetcode] [SQL] notes
Chapter 2: find the box array, complete number in the specified interval, and improve the complete number in the specified interval
EGO Planner代码解析bspline_optimizer部分(1)
Chapitre 1: le roi de shehan a mal calculé
Flume learning notes
UE source code analysis: uccharactermovementcomponent - rootmotion
The way to treat feelings
Sentinel source code analysis part I sentinel overview
Scrape crawler framework
第二章:4位卡普雷卡数,搜索偶数位卡普雷卡数,搜索n位2段和平方数,m位不含0的巧妙平方数,指定数字组成没有重复数字的7位平方数,求指定区间内的勾股数组,求指定区间内的倒立勾股数组
2022.2.14 Li Kou - daily question - single element in an ordered array
第一章: 舍罕王失算
Leetcode 1189. Maximum number of balloons (special character count)
Pecan — @expose()
Analysis of dart JSON encoder and decoder
Record: writing MySQL commands
Pecan - route
Using the visualization results, click to appear the corresponding sentence
2022-06-28 网工进阶(十三)IS-IS-路由过滤、路由汇总、认证、影响ISIS邻居关系建立的因素、其他命令和特性