postgres - 违反检查约束错误

时间:2015-10-13 13:13:45

标签: postgresql

这是我的表创建脚本,我在为order_until字段分配任何值之前检查order_type。

   CREATE TABLE merchants
    (
      id serial NOT NULL,
      name character varying(100),
      merchant_image bytea,
      merchant_logo bytea,
      merchant_longitude double precision,
      merchant_latitude double precision,
      merchant_address character varying(100),
      merchant_phone character varying(50),
      order_type character varying(15),
      open_until time without time zone,
      order_until time without time zone,
      CONSTRAINT merchants_pkey PRIMARY KEY (id),
      CONSTRAINT unique_name UNIQUE (name),
      CONSTRAINT merchants_check CHECK (
    CASE
        WHEN order_type::text = 'NO_ORDERING'::text THEN order_until = '00:00:00'::time without time zone
        ELSE NULL::boolean
    END),
      CONSTRAINT merchants_order_type_check CHECK (order_type::text = ANY (ARRAY['TAKE_AWAY'::character varying, 'HOME_DELIVERY'::character varying, 'NO_ORDERING'::character varying]::text[]))
    )

当我尝试在表格中插入值时出现错误:关系“商家”的新行违反了检查约束“merchants_check” 这是我的插入脚本:

INSERT INTO MERCHANTS(NAME,MERCHANT_ADDRESS,MERCHANT_PHONE,ORDER_TYPE,OPEN_UNTIL,ORDER_UNTIL)
VALUES('Test','Test address1','1234567','NO_ORDERING','22:00:00'::time,'20:00:00'::time);

任何人都有任何建议如何解决这个问题?

0 个答案:

没有答案