B
B
Black back2019-12-16 12:49:55
PostgreSQL
Black back, 2019-12-16 12:49:55

Why doesn't changing the table work?

Why does not work like everything is done correctly. The table has already been created. This is just an example

create table persons(
rols varchar(30) not null
);

alter table persons 
alter column rols
add check (rols in('registrator', 'coordinator', 'user'))

Before check, the error says
LINE 3: add check (rols in('registrator', 'coordinator', 'user'))

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Melkij, 2019-12-16
@melkij

Because there is no such alter column syntax.

S
Sergey c0re, 2019-12-19
@erge

Melkij , the case speaks)
see PostgreSQL CHECK Constraint

ALTER TABLE persons 
   ADD CONSTRAINT persons_check_rols CHECK (rols in('registrator', 'coordinator', 'user'));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question