Re: tricky CHECK condition

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Arcady Genkin <a(dot)genkin(at)utoronto(dot)ca>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: tricky CHECK condition
Date: 2000-05-23 05:11:39
Message-ID: 422.959058699@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Arcady Genkin <a(dot)genkin(at)utoronto(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Janet 2000-05-23 06:21:44
Previous Message Arcady Genkin 2000-05-23 04:52:40 Re: tricky CHECK condition