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