我想创建与此类似的东西
CHECK (ALL(scopes) IN ('read', 'write', 'delete', 'update'))
scopes
这是表中的字段text[]
,我想确保此数组中的所有值都是以上值之一。有什么意见吗?还有可能通过SELECT
从另一个表中获取这些值吗?
我已经看到了以下解决方案,但我想知道是否有一个更简单的解决方案。
Postgresql check constraint on all individual elements in array using function
答案 0 :(得分:4)
使用<@
operator:
for fle in all_files:
# open the file and then call .read() to get the text
with open(os.path.join(path, fle),"rb") as f:
text = f.read()
new_list.append(text)
不知道您的确切用例,但我希望使用更规范的解决方案:将这四个操作放在一个单独的表中,该表可以更新。然后,您可以使用外键而不是检查约束。如果必须更新这四个关键字,则无需更改表DDL,而只需更改外部表中的值即可。