DatabaseStatusSyntax FamilyMin Version
PostgreSQL full sql-standard -
MySQL none - -
MariaDB none - -
Oracle none - -
SQL Server none - -
SQLite none - -
Redshift none - -
DB2 none - -
Snowflake none - -
BigQuery none - -

Compare Databases

Database Details

PostgreSQL full
-- Prevent double-booking of a room for overlapping time periods
-- Requires: CREATE EXTENSION IF NOT EXISTS btree_gist;
CREATE TABLE bookings (
  room_id  INT,
  during   TSRANGE,
  CONSTRAINT no_overlapping_bookings
    EXCLUDE USING gist (
      room_id WITH =,
      during  WITH &&
    )
);

-- Partial exclusion constraint
CREATE TABLE appointments (
  doctor_id INT,
  slot      TSRANGE,
  cancelled BOOLEAN DEFAULT FALSE,
  CONSTRAINT no_double_booking
    EXCLUDE USING gist (doctor_id WITH =, slot WITH &&)
    WHERE (NOT cancelled)
);
  • Backed by a GiST index; mixing scalar types with range types needs the btree_gist extension (shipped with PostgreSQL).
  • A WHERE clause narrows the constraint to a subset of rows (partial exclusion).
  • USING can target SP-GiST or other index types when the operator class supports them.
MySQL none
  • Not supported. Use BEFORE INSERT / BEFORE UPDATE triggers to reject overlapping rows.
MariaDB none
  • Not supported. Use BEFORE-triggers or application code to prevent overlaps.
Oracle none
  • Not supported. Use BEFORE-triggers, or encode overlap rules in a materialized view with a UNIQUE constraint on the conflict key.
SQL Server none
  • Not supported. Filtered unique indexes cover equality-style exclusion but not range overlap. Use INSTEAD OF triggers or application-level locking for the overlap case.
SQLite none
  • Not supported. Use triggers to detect overlapping rows.
Redshift none
  • Not supported, and no triggers either. Enforce overlap rules in the application or ETL.
DB2 none
  • Not supported. Use BEFORE-triggers to detect overlap.
Snowflake none
  • Not supported, and no triggers either. Enforce overlap rules upstream.
BigQuery none
  • Not supported, and no triggers either. Enforce overlap rules upstream.