Sqlite确保输入数据的长度正确 [英] Sqlite make sure input data is correct length

查看:110
本文介绍了Sqlite确保输入数据的长度正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提出问题,我得到了一个很好的答案,但带来了许多其他问题。

I asked a question to which I got a great answer but which bring many other questions.

说我创建了一个表:

 CREATE TABLE test(my_id INTEGER(2));

如何确保在INSERTING数据插入(或从csv入口)完全一个INTEGER(2),不是INTEGER(1)或任何其他动态伸展到..?
如果我不能在这里没有内存/性能问题?

How can I make sure that when INSERTING data in there (or imporing from csv atually) the field is exactly an INTEGER(2), not INTEGER(1) or anything else it would dynamically stretch to..? If I cannot are there no memory/performance issues with this?

谢谢!

推荐答案

从CSV文件导入的所有值都是字符串(但类型关联<

All values imported from CSV files are strings (but type affinity might change that).

为了确保值在一定范围内,添加一个明确的约束:

To ensure that values are in a certain range, add an explicit constraint:

CREATE TABLE test(
    my_id INTEGER CHECK (my_id BETWEEN 0 AND 100)
);

无论如何声明它们,整数值都存储在1,2,3,4, 6或8个字节,取决于值的大小。

Regardless of how they're declated, integer values are stored in 1, 2, 3, 4, 6, or 8 bytes depending only on the magnitude of the value.

这篇关于Sqlite确保输入数据的长度正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆