0

I've run into an issue with adding a check constraint to one of my tables in my database. The check constraint's purpose is to make sure that times past 12:00 on a Wednesday cannot exist. This is what I've got:

alter table module_daytime
    add CONSTRAINT CHK_TimeWED CHECK (Time BETWEEN '9:00' AND '12:00' AND Day='Wednesday')

I have already added data that abides to this rule into the table, however, when I try to add it, it still says that a row in my table violates said rule. What is wrong?

philipxy
  • 14,867
  • 6
  • 39
  • 83
Keeno98
  • 1
  • 2

1 Answers1

0

I cannot reproduce your issue (see below). Can you try to reproduce your table and test data for JUST that constraint.

create table module_daytime("time" time, day varchar(20) );
insert into module_daytime values ('12:00', 'Wednesday');
1 rows affected
select * from module_daytime;
time     | day      
:------- | :--------
12:00:00 | Wednesday
alter table module_daytime
    add CONSTRAINT CHK_TimeWED CHECK (Time BETWEEN '9:00' AND '12:00' AND Day='Wednesday');
insert into module_daytime values ('12:00', 'Wednesday');
1 rows affected
insert into module_daytime values ('12:01', 'Wednesday');
ERROR:  new row for relation "module_daytime" violates check constraint "chk_timewed"
DETAIL:  Failing row contains (12:01:00, Wednesday).

dbfiddle here

Paul Maxwell
  • 33,002
  • 3
  • 32
  • 51