Re: Feature request - function-based deferrable uniques. - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: Feature request - function-based deferrable uniques.
Date
Msg-id 20100401140956.GB3014@alvh.no-ip.org
Whole thread Raw
In response to Feature request - function-based deferrable uniques.  (Dmitry Fefelov <fozzy@ac-sw.com>)
Responses Re: Feature request - function-based deferrable uniques.  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Feature request - function-based deferrable uniques.  (Dmitry Fefelov <fozzy@ac-sw.com>)
List pgsql-hackers
Dmitry Fefelov wrote:

> So, deferrable uniques now can be based on column/columns list only. It will 
> be very useful if there will be possibility to specify functions in this list. 
> Is it possible? 

Sure -- use CREATE UNIQUE INDEX.

alvherre=# create function singleton(int) returns int immutable language sql as $$ select 1 $$;
CREATE FUNCTION
alvherre=# create table singleton (a int);
CREATE TABLE
alvherre=# create unique index only_one on singleton (singleton(a));
CREATE INDEX
alvherre=# insert into singleton values (3);
INSERT 0 1
alvherre=# insert into singleton values (6);
ERROR:  llave duplicada viola restricción de unicidad «only_one»


The reason it's not supported in table_constraint, IIUC, is that the
standard doesn't allow it, and that syntax is standards-mandated.
CREATE INDEX, however, is not.

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [DOCS] Streaming replication document improvements
Next
From: "Ross J. Reedstrom"
Date:
Subject: Re: Alias to rollback keyword