当前位置:网站首页>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
边栏推荐
- Chapter 1: King Shehan miscalculated
- These problems should be paid attention to in the production of enterprise promotional videos
- [new year job hopping season] test the technical summary of interviewers' favorite questions (with video tutorials and interview questions)
- What is the content of game modeling
- I study database at station B (4): DQL
- Pecan — Overview
- Analyse du Code du planificateur ego bspline Section Optimizer (1)
- 第一章: 舍罕王失算
- The space of C disk is insufficient, and the computer becomes stuck. Quickly expand the capacity of C disk to make the system more smooth
- Chapter 1: seek common? Decimal and S (D, n)
猜你喜欢

Common text labels

Summary of composition materials for 2020 high-frequency examination center of educational resources

【Proteus仿真】用24C04与1602LCD设计的简易加密电子密码锁

These problems should be paid attention to in the production of enterprise promotional videos

Merge K ascending linked lists

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

Free year-end report summary template Welfare Collection

EGO Planner代码解析bspline_optimizer部分(3)

东数西算拉动千亿产业,敢啃“硬骨头”的存储厂商才更有机会

第一章: 舍罕王失算
随机推荐
If the warehouse management communication is not in place, what problems will occur?
Ego planner code parsing Bspline_ Optimizer section (2)
[proteus simulation] a simple encrypted electronic password lock designed with 24C04 and 1602LCD
Record: writing MySQL commands
ActiveMQ的基础
03 -- QT OpenGL EBO draw triangle
Next spread
Php based campus lost and found platform (automatic matching push)
Thesis study - 7 Very Deep Convolutional Networks for Large-Scale Image Recognition (3/3)
Use unique_ PTR forward declaration? [repetition] - forward declaration with unique_ ptr? [duplicate]
第一章:求n的阶乘n!
Octopus online ecological chain tour Atocha protocol received near grant worth $50000
Chapter 1: recursively find the factorial n of n!
第二章:4位卡普雷卡数,搜索偶数位卡普雷卡数,搜索n位2段和平方数,m位不含0的巧妙平方数,指定数字组成没有重复数字的7位平方数,求指定区间内的勾股数组,求指定区间内的倒立勾股数组
Chapter 2: find the box array, complete number in the specified interval, and improve the complete number in the specified interval
【水质预测】基于matlab模糊神经网络水质预测【含Matlab源码 1923期】
Chapter 2: 4-digit Kaplan number, search even digit Kaplan number, search n-digit 2-segment sum square number, m-digit ingenious square number without 0, specify the number to form a 7-digit square nu
What does a really excellent CTO look like in my eyes
Summary of 90 day learning materials and notes of Zhang Fei's actual electronic hardware engineer
2022-07-02 网工进阶(十五)路由策略-Route-Policy特性、策略路由(Policy-Based Routing)、MQC(模块化QoS命令行)