losthorse
losthorse

Reputation: 1570

Postgres 9.3 - Limit value (based on value in different table with foreign key)

I have two tables that look like this:

CREATE TABLE "schema"."TableOne" (
    "TableOneID" SERIAL PRIMARY KEY,
    "TimeRange" TSTZRANGE
);

CREATE TABLE "schema"."TableTwo" (
    "TableTwoID" SERIAL PRIMARY KEY,
    "TableOneID" INTEGER FOREIGN KEY ("SoulID") REFERENCES "schema"."TableOne" ("TableOneID")
    "TimeRange" TSTZRANGE
);

I want to make sure that any value in "TableTwo"."TimeRange" is contained by the range in "TableOne"."TimeRange" where "TableOne"."TableOneID" = "TableTwo"."TableOneID"

I have read the documentation (8.17.10. Constraints on Ranges) several times and can't find a way to make this happen... any ideas?

Upvotes: 1

Views: 79

Answers (1)

You can't yet do that in PostgreSQL. The pgsql-hackers listserv recommends using serializable transactions to change data, and using triggers to implement the constraints.

Upvotes: 1

Related Questions