Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database postgresql中带有字母(非数字)的列的数据类型_Database_Postgresql_Database Schema - Fatal编程技术网

Database postgresql中带有字母(非数字)的列的数据类型

Database postgresql中带有字母(非数字)的列的数据类型,database,postgresql,database-schema,Database,Postgresql,Database Schema,对于在postgresql中只能包含字母而不能包含数字的表中声明列,哪种数据类型最合适?最好是在varchar上使用check约束创建一个域 create domain textonly text check (value not similar to '%[0-9]%'); 然后,您可以将其用作阻止数字的数据类型 pagetest=# create table dtest (test textonly); CREATE TABLE pagetest=# insert into dtest v

对于在postgresql中只能包含字母而不能包含数字的表中声明列,哪种数据类型最合适?

最好是在varchar上使用check约束创建一个域

create domain textonly text check (value not similar to '%[0-9]%');
然后,您可以将其用作阻止数字的数据类型

pagetest=# create table dtest (test textonly);
CREATE TABLE
pagetest=# insert into dtest values ('abc');
INSERT 0 1
pagetest=# insert into dtest values ('ab2c');
ERROR:  value for domain textonly violates check constraint "textonly_check"
pagetest=# 
谢谢:)你的答案稍加修改就成功了。