繁体   English   中英

定义涉及模式匹配的类型

[英]define a type involving pattern matching

如果我想在PostgreSQL中定义一个类型,该类型应如下所示:

[A-Z]{4}[0-9]{4}

这是在进行模式匹配。 我该怎么办?

CREATE DOMAIN可能适合您。

create domain NEWTYPE as char(8)
  constraint newtype_regex not null check (value ~ '[A-Z]{4}[0-9]{4}');

我猜大概not null 像固有数据类型一样使用它。

create table test (
  nt NEWTYPE
);

冒烟试验。

insert into test values ('ABCD0123'); -- Succeeds
insert into test values ('ABCD012');  -- Fails
insert into test values (null);       -- Fails
insert into test values ('abcd0123'); -- Fails

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM