#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    1
    Rep Power
    0

    Time postgre check


    how do we do this?

    startTime time not null,
    endTime time (check endTime > startTime), -- if end time is not null
    startDate date not null,
    endDate date (check endDate > startDate), --if end date is not null
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,784
    Rep Power
    348
    In Postgres (note the s at the end, "Postgre" is not the short form of PostgreSQL), you have to define the check constraint at the end:

    Code:
    CREATE TABLE foo
    (
       startTime   time not null,
       endTime     time check (endTime is null or endTime > startTime),
       startDate   date not null,
       endDate     date check (endDate is null or endDate > startDate)
    )

IMN logo majestic logo threadwatch logo seochat tools logo