Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 773B02E003B for ; Mon, 18 Feb 2008 07:30:26 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 25207-01 for ; Mon, 18 Feb 2008 07:30:19 -0400 (AST) Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by postgresql.org (Postfix) with ESMTP id 69CD22E0039 for ; Mon, 18 Feb 2008 07:30:25 -0400 (AST) Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by wwwmaster.postgresql.org (8.13.8/8.13.8) with ESMTP id m1IBUNjR060027 for ; Mon, 18 Feb 2008 11:30:23 GMT (envelope-from www@wwwmaster.postgresql.org) Received: (from www@localhost) by wwwmaster.postgresql.org (8.13.8/8.13.8/Submit) id m1IBUNdu060026; Mon, 18 Feb 2008 11:30:23 GMT (envelope-from www) Date: Mon, 18 Feb 2008 11:30:23 GMT Message-Id: <200802181130.m1IBUNdu060026@wwwmaster.postgresql.org> To: pgsql-bugs@postgresql.org Subject: BUG #3965: UNIQUE constraint fails on long column values From: "Juho Saarikko" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/159 X-Sequence-Number: 19726 The following bug has been logged online: Bug reference: 3965 Logged by: Juho Saarikko Email address: juhos@mbnet.fi PostgreSQL version: 8.3RC2 Operating system: Linux Description: UNIQUE constraint fails on long column values Details: It is impossible to add an UNIQUE constraint which includes columns with long values. The reason seems to be that UNIQUE is implemented using b-tree index, which cannot handle values longer than 8191 bytes. While I didn't test, I'd imagine that this would also mean that any attempt to insert such values to an already unique column would fail. It is propably impossible to fix this in a simple way, since it is an inherent result of the underlying storage specification rather than a mere programming error, so the documentation needs to be updated to warn about this. I suggest implementing unique hash indexes and automatically creating one (and turning the b-tree index into a non-unique one) when a large value is inserted to fix this. Alternatively, fix b-trees so they can handle large values; however, a hash index should be far more efficient for this specific case, since the size of a hash is independent of pre-hash data size. Exact error message: ****************** kuvat=# alter table pictures ADD constraint pic_unique unique (safe); NOTICE: 00000: ALTER TABLE / ADD UNIQUE will create implicit index "pic_unique" for table "pictures" LOCATION: DefineIndex, indexcmds.c:434 ERROR: 54000: index row requires 47148 bytes, maximum size is 8191 LOCATION: index_form_tuple, indextuple.c:170