SQLITE 自定义数据类型? [英] SQLITE Custom DataTypes?

查看:50
本文介绍了SQLITE 自定义数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 SQLITE 还很陌生,我注意到只有 4 种数据类型,但我在网上看到了人们输入自己的数据类型的示例.我真的不明白这一点,想知道是否有人可以向我解释这一点.例如,我看到一个包含日期的列,并且给出的数据类型是不存在的时间戳.它默认是什么?当您自己制作时,它是否默认为文本?

I am fairly new to SQLITE and I noticed that there are only a 4 datatypes but I see examples online where people are putting in their own datatypes. I don't really understand this and was wondering if someone could explain that to me. For example I see a column that will hold a date and the datatype that was given was timestamp which does not exist. What does it default to? Does it default to a text when you make your own?

推荐答案

sqlite3 使用动态类型系统.只有五个存储类:NULL、整数、实数、文本和 blob.(来源:SQLite 版本 3 中的数据类型.)

sqlite3 uses a dynamic type system. There are only five storage classes: NULL, integer, real, text and blob. (Source: Datatypes In SQLite Version 3.)

而且,引用该页面:

SQLite 版本 3 数据库中的任何列(INTEGER PRIMARY KEY 列除外)都可用于存储任何存储类的值.

Any column in an SQLite version 3 database, except an INTEGER PRIMARY KEY column, may be used to store a value of any storage class.

除了整数主键 例外,SQLite 根本不强制类型.这意味着您在 create table 中输入的类型名称纯粹是提供信息.

Apart from the integer primary key exception, SQLite doesn't enforce types at all. Which means that the type name you put in your create table is purely informative.

create table mytab (a apples, b bananas);

是有效的 create table 语句.您可以在两列中插入时间戳、文本、blob(不是说您应该,但您可以).

is a valid create table statement. You can insert timestamps, text, blobs into both columns (not saying that you should, but you can).

查看类型系统的链接参考文档以获取更多信息.

Look at the linked reference documentation for the type system for more information.

sqlite> create table mytab (a apples, b bananas);
sqlite> insert into mytab values (CURRENT_TIME, NULL);
sqlite> insert into mytab values ('hello', 3.14159);
sqlite> select * from mytab;
14:59:18|
hello|3.14159

直接回答您的问题:没有默认值.存储类型与存储在数据库中的每个值相关联,而不是与表的列相关联.

To answer your question directly: there is no default. A storage type is associated with each value stored in the database, not to columns of a table.

这篇关于SQLITE 自定义数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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