I have a layer of parcels and want to disable the possibility of adding a bad grammar entry or change in the municipalities ("muni" column) and I have tried the following which should work and worked for others:
"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'
)
This is how it looks in 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'
));
So, the idea is that when a new entry is created, the editor can only pick from these. I am doing this as part of a course, however, I am using a newer version of pgadmin 4 and PostgreSQL 12. Now, I have located https://github.com/sqlalchemy/sqlalchemy/issues/4463 that some syntax is deprecated but I am not tech-savvy still to understand whether that might be causing the issue or not. Because after adding the constraint, I can change the 'VILLAGE OF GROTON' to whatever and don't receive a constraint error that I should.
The issue was rather silly. If you have used pgadmin 3, the issue would turn up immediately after you try to enter it just like in ArcGIS in the table and won't allow you to leave unless you put in a correct solution. However, in pgadmin 4, you get to put the wrong name that goes against the constraint and only when you want to save your edits it eventually gives the same error it used to give before. So, my bad for not catching up on this sooner but I was just used to the old way.