约束自定义PostgreSQL类型?

时间:2015-03-30 12:38:49

标签: sql postgresql

有没有办法直接向PostgreSQL中的类型添加约束?

我使用PostgreSQL 9.4并且我最初定义了我的类型:

create type indoors_map_location as (x bigint, y bigint, z bigint);

我无法找到一种方法来为我的类型定义in the documentation添加约束,所以我通过定义为现有数据类型添加约束的域来解决这个问题,然后在我的复合类型定义中使用它们,像这样:

create domain non_nullable_bigint bigint not null;
create domain non_negative_bigint non_nullable_bigint check (value >= 0);
create type indoors_map_location as (x non_negative_bigint, y non_negative_bigint, z non_nullable_bigint);

有更直接的方法来解决这个问题吗?或者我的方法常见吗?您是否知道向类型定义添加约束是计划特征还是由于某种原因而被遗漏?

0 个答案:

没有答案