Answer the question
In order to leave comments, you need to log in
How do I set a two-condition check constraint?
I'm trying to organize adding a column like this
ALTER TABLE main_owner ADD COLUMN fsex varchar(1) NOT NULL check ('M' or 'W');
ERROR: invalid input syntax for type boolean: "M"
Answer the question
In order to leave comments, you need to log in
ALTER TABLE main_owner ADD COLUMN fsex varchar(1) NOT NULL check (fsex = 'M' or fsex = 'W');
ALTER TABLE main_owner ADD COLUMN fsex varchar(1) NOT NULL check (fsex IN('M', 'W'));
For enums, you can use native enum
melkij=> create type gender as enum('M','W');
CREATE TYPE
melkij=> create table foo (f gender);
CREATE TABLE
melkij=> insert into foo values('M');
INSERT 0 1
melkij=> insert into foo values('F');
ОШИБКА: неверное значение для перечисления gender: "F"
СТРОКА 1: insert into foo values('F');
^
melkij=> insert into foo values('');
ОШИБКА: неверное значение для перечисления gender: ""
СТРОКА 1: insert into foo values('');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question