Re: tricky CHECK condition - Mailing list pgsql-general

From Tom Lane
Subject Re: tricky CHECK condition
Date
Msg-id 422.959058699@sss.pgh.pa.us
Whole thread Raw
In response to tricky CHECK condition  (Arcady Genkin <a.genkin@utoronto.ca>)
List pgsql-general
Arcady Genkin <a.genkin@utoronto.ca> writes:
> I want to check values of `track_number' to be unique for the
> disk.

Not sure if it can be done with a CHECK condition, but the traditional
solution is to create a unique index on the two columns:

create unique index tracks_disk_track_i on tracks(disk_id, track_number);

Updating an index should be a lot faster than running a whole subquery
for each insert, and the planner may be able to use the index to speed
up other queries too.  So, it's a win all round...

            regards, tom lane

pgsql-general by date:

Previous
From: Arcady Genkin
Date:
Subject: Re: tricky CHECK condition
Next
From: "Janet"
Date:
Subject: