I'm trying to create a conditional check constraint in postgresql. When a_type is 'a', I want the b to only contain digit. When a_type is not 'a', I want b to contain any characters. How would I accomplish this? I have this now:
EDIT: I think this should work.
CONSTRAINT test CHECK (a_type <> 'a' AND b ~* '^.$') OR (a_type = 'a' AND b ~* '^[0-9]+$')