Überlappende Bedingung für Postgres-Datum

Ich habe einen Tisch wie diesen:

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

Ich möchte überlappende Intervalle als gegeben verbieten(account_id, product_id)

EDIT: Ich habe etwas gefunden:

CREATE TABLE test (                                                                                                
    from_ts TIMESTAMPTZ,
    to_ts TIMESTAMPTZ,
    account_id INTEGER,
    product_id INTEGER,
    CHECK ( from_ts < to_ts ),
    CONSTRAINT overlapping_times EXCLUDE USING GIST (
        account_id WITH =,
        product_id WITH =,
        box(
            point( extract(epoch FROM from_ts at time zone 'UTC'), extract(epoch FROM from_ts at time zone 'UTC') ),
            point( extract(epoch FROM to_ts at time zone 'UTC') , extract(epoch FROM to_ts at time zone 'UTC') )
        ) WITH &&
    )
);

Wenn Sie mehr darüber wissen wollenhttp://www.depesz.com/2010/01/03/waiting-for-8-5-exclusion-constraints/

Mein einziges Problem ist, dass es nicht mit Nullwerten als Endzeitstempel funktioniert. Ich habe darüber nachgedacht, es durch unendliche Werte zu ersetzen, aber es funktioniert nicht so gut.

Antworten auf die Frage(4)

Ihre Antwort auf die Frage