Re: Create unique index or constraint on part of a column

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: Ruben Blanco <rubenblan(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Create unique index or constraint on part of a column
Date: 2011-03-07 23:38:03
Message-ID: 1299541083.7300.3.camel@jdavis-ux.asterdata.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 2011-03-07 at 23:30 +0000, Ruben Blanco wrote:
> Hi:
>
> Is there anyway to create a unique index or constraint on part of a
> column?
>
> Something like this, but something that works ;-)
>
> ALTER TABLE invoices
> ADD CONSTRAINT cons UNIQUE (EXTRACT(YEAR FROM invoice_date),
> innvoice_number);

CREATE UNIQUE INDEX invoices_constraint_idx ON invoices
(EXTRACT(YEAR FROM invoice_date), invoice_number);

Regards,
Jeff Davis

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Glenn Maynard 2011-03-07 23:39:22 Re: Why count(*) doest use index?
Previous Message Thomas Kellerer 2011-03-07 23:35:53 Re: Create unique index or constraint on part of a column