怎么创建一个创建MySQL数据库中的datetime类型
作者:NorthPath
时间:2023-04-27
来源:互联网
浏览:0
环境系统平台:MicrosoftWindows(64-bit)10版本:4.5瀚高数据库中支持使用以下语句创建用户定义的数据类型:CREATEDOMAIN:它创建了一个用户定义的数据类型,可以有可选的约束,基于其他基本类型,实质是定义一个域。CREATETYPE:它通常用于使用存储过程创建复合类型(两种或多种数据类型混合的数据类型)。一、domain用法及示例假如有以下表结构:createtabletest_domain(idvarchar,md5textnotnullcheck(length(md5)=
环境系统平台:Microsoft Windows (64-bit) 10版本:4.5
瀚高数据库中支持使用以下语句创建用户定义的数据类型:
CREATE DOMAIN:它创建了一个用户定义的数据类型,可以有可选的约束,基于其他基本类型,实质是定义一个域。CREATE TYPE:它通常用于使用存储过程创建复合类型(两种或多种数据类型混合的数据类型)。
一、domain用法及示例
假如有以下表结构:
create table test_domain (id varchar,md5 text not null check(length(md5)=32));
其中md5列的类型及约束,可以定义一个domain来抽象,如下:
highgo=# create domain md5 as
highgo-# text not null
highgo-# check (
highgo(# length(value) = 32
highgo(# );
CREATE DOMAIN
highgo=#
highgo=# \dD md5
List of domains
Schema | Name | Type | Collation | Nullable | Default | Check
--------+------+------+-----------+----------+---------+----------------------------
public | md5 | text | | not null | | CHECK (length(VALUE) = 32)
(1 row)
highgo=# create table test_domain (id varchar,md5 md5);
CREATE TABLE
highgo=# insert into test_domain values('1','2');
ERROR: value for domain md5 violates check constraint "md5_check"
highgo=# insert into test_domain values('2','76a2173be6393254e72ffa4d6df1030a');
INSERT 0 1二、创建MySQL中datetime类型
highgo=# create domain datetime as timestamp without time zone; highgo=# create table t_time (id int,create_time datetime); CREATE TABLE highgo=# \d+ t_time Table "public.t_time" Column | Type | Collation | Nullable | Default | Storage | Stats target | Description -------------+----------+-----------+----------+---------+---------+--------------+------------- id | integer | | | | plain | | create_time | datetime | | | | plain | | Access method: heap highgo=# insert into t_time values (1,now()),(2,now()); INSERT 0 2 highgo=# highgo=# select * from t_time; id | create_time ----+---------------------------- 1 | 2021-08-03 19:28:11.207324 2 | 2021-08-03 19:28:11.207324 (2 rows)
三、create type用法及示例
CREATE TYPE name AS
( [ attribute_name data_type [ COLLATE collation ] [, ... ] ] )
CREATE TYPE name AS ENUM
( [ 'label' [, ... ] ] )
CREATE TYPE name AS RANGE (
SUBTYPE = subtype
[ , SUBTYPE_OPCLASS = subtype_operator_class ]
[ , COLLATION = collation ]
[ , CANONICAL = canonical_function ]
[ , SUBTYPE_DIFF = subtype_diff_function ]
)
CREATE TYPE name (
INPUT = input_function,
OUTPUT = output_function
[ , RECEIVE = receive_function ]
[ , SEND = send_function ]
[ , TYPMOD_IN = type_modifier_input_function ]
[ , TYPMOD_OUT = type_modifier_output_function ]
[ , ANALYZE = analyze_function ]
[ , INTERNALLENGTH = { internallength | VARIABLE } ]
[ , PASSEDBYVALUE ]
[ , ALIGNMENT = alignment ]
[ , STORAGE = storage ]
[ , LIKE = like_type ]
[ , CATEGORY = category ]
[ , PREFERRED = preferred ]
[ , DEFAULT = default ]
[ , ELEMENT = element ]
[ , DELIMITER = delimiter ]
[ , COLLATABLE = collatable ]
)
CREATE TYPE name创建示例:
CREATE TYPE compfoo AS (f1 int, f2 text);
CREATE FUNCTION getfoo() RETURNS SETOF compfoo AS $$
SELECT fooid, fooname FROM foo
$$ LANGUAGE SQL;
CREATE TYPE bug_status AS ENUM ('new', 'open', 'closed');
CREATE TABLE bug (
id serial,
description text,
status bug_status
);
CREATE TYPE float8_range AS RANGE (subtype = float8, subtype_diff = float8mi);
作者最新文章
贵州省住建厅与贝壳集团签署旅居战略合作:五大维度落地方案解析
2026-09-08 18:13
上海链家安住APP:业主主动卖房功能与成交数据解析
2026-09-08 18:11
如何批量将PPT转成PDF格式?PPT转PDF工具怎么选?
2026-09-04 16:03
PDF文件怎么压缩?3个小技巧帮你减小体积
2026-09-03 18:03
小批量试产总结报告:新产品量产导入评审实战指南
2026-09-02 19:48
上一篇:
点对点网络详解
热门文章
更多
精品专题
更多
Mac软件
更多
WINDOWS
更多
Windows 10
Windows
Windows 10 是一款微软推出的经典操作系统,拥有硬件兼容性与多任务处理能力。它更偏向把系统状态查看和常用调节动作放在一起,适合需要持续观察和微调设备状态的场景。
极度公式
Windows/macOS/Linux
极度公式是一款跨平台专业LaTeX公式识别编辑软件,支持OCR公式识别和多平台编辑。和使用说明,避免使用,享受完整功能与稳定支持。做扫描整理、文字提取和表格转换时,它能把识别后的处理步骤接得更顺,资料录入这类场景会省下不少时间。
















