Postgres date overlapping constraint

前端 未结 4 1132
鱼传尺愫
鱼传尺愫 2020-12-14 08:22

I have a table like this:

date_start    date_end     account_id    product_id
2001-01-01    2001-01-31   1             1
2001-02-01    2001-02-20   1                 


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 08:37

    How to create unique constraint to a group of columns :

     CREATE TABLE table (
        date_start date,
        date_end  date,
        account_id integer,
        UNIQUE (account_id , date_start ,date_end) );
    

    in your case you will need to ALTER TABLE if the table already exists, check the documentation it would be helpful for you :
    - DDL Constraints
    - ALTER Table

提交回复
热议问题