如何在 postgres 系统目录 tables/views 上创建外键?

How to make foreign key on postgres system catalog tables/views?

在我们的 table 之一中,我们有以下列:

id, date, name, timezone(string)

如何确保时区只能是pg_timezone_namestable中的一个? 我们如何为此创建外键?

这不是我通常会推荐的,但您可以使用 check 约束条件 returns 错误而不是 true 或 false:

 check (timezone( timezone, '2000-01-01'::timestamp) is not null)

Here就是一个例子。