我有一个包裹层,并希望避免在市政当局中添加错误的语法条目或更改的可能性(“市政”专栏,我已经尝试了以下可行且对其他人有用的方法:
"MUNI" IN ( 'CITY OF ITHACA',
'NEWFIELD',
'TOWN OF CAROLINE',
'TOWN OF DANBY',
'TOWN OF DRYDEN',
'TOWN OF ENFIELD',
'TOWN OF GROTON',
'TOWN OF ITHACA',
'TOWN OF LANSING',
'TOWN OF NEWFIELD',
'TOWN OF ULYSSES',
'VILLAGE OF CAYUGA HEIGHTS',
'VILLAGE OF DRYDEN',
'VILLAGE OF FREEVILLE',
'VILLAGE OF GROTON',
'VILLAGE OF LANSING',
'VILLAGE OF TRUMANSBURG'
)
这是它在SQL中的外观
ALTER TABLE public.parcels2007
ADD CONSTRAINT two CHECK ("MUNI" IN ( 'CITY OF ITHACA',
'NEWFIELD',
'TOWN OF CAROLINE',
'TOWN OF DANBY',
'TOWN OF DRYDEN',
'TOWN OF ENFIELD',
'TOWN OF GROTON',
'TOWN OF ITHACA',
'TOWN OF LANSING',
'TOWN OF NEWFIELD',
'TOWN OF ULYSSES',
'VILLAGE OF CAYUGA HEIGHTS',
'VILLAGE OF DRYDEN',
'VILLAGE OF FREEVILLE',
'VILLAGE OF GROTON',
'VILLAGE OF LANSING',
'VILLAGE OF TRUMANSBURG'
));
因此,想法是当创建新条目时,编辑者只能从中选择。我是在课程中进行此操作的,但是,我使用的是pgadmin 4和PostgreSQL 12的较新版本。现在,我确定https://github.com/sqlalchemy/sqlalchemy/issues/4463某些语法已被弃用,但我仍然不懂技术,以了解是否可能是造成问题的原因,也可能不是。因为添加约束后,我可以将“ GROTON OF GROTON”更改为任何值,并且不会收到应有的约束错误。