X-Original-To: pgsql-sql@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id A3B75924C56 for ; Fri, 23 May 2003 11:49:15 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193:10024]) (amavisd-new) with ESMTP id 71866-06 for ; Fri, 23 May 2003 11:49:08 -0400 (EDT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by developer.postgresql.org (Postfix) with ESMTP id 72089924CBF for ; Fri, 23 May 2003 11:17:39 -0400 (EDT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 9925ED696; Fri, 23 May 2003 08:17:32 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 8EC705C11; Fri, 23 May 2003 08:17:32 -0700 (PDT) Date: Fri, 23 May 2003 08:17:32 -0700 (PDT) From: Stephan Szabo To: Oleg Bartunov Cc: Jan Wieck , Luis Sousa , Richard Huxton , Filipe Bonjour , Subject: Re: Can arrays reference primary keys in CREATE TABLE? In-Reply-To: Message-ID: <20030523081208.D69228-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new X-Archive-Number: 200305/473 X-Sequence-Number: 13638 On Fri, 23 May 2003, Oleg Bartunov wrote: > On Thu, 22 May 2003, Jan Wieck wrote: > > > Luis Sousa wrote: > > > Jan Wieck wrote: > > >> You used a trigger to check something, but unless you have a full set of > > >> said triggers and they do the locking as well, you do not have > > >> referential integrity. > > >> > > >> > > >> Jan > > >> > > >> > > > I guess you are right. > > > I'll have to write a trigger for UPDATE or DELETE. How can I do the lock > > > only on that record ? > > > > That exactly is the problem with arrays here. You can't index an array > > in a way so that you can effectively select all rows who's array > > contains a particular value. Your trigger can only select all of them > > there is contrib/intarray which could be used for indexed access to > array of integers. In principle, it should be not difficult to > generalize this module to support many types. Yeah, that should get around locking all the rows. It will still mean that deadlocks are even more likely to occur with such tables than with the normal constraint conditions however (locking the row containing one element we're looking for effectively locks for all of those values). As a side note, there are some other issues with making the constraint work for non-no action constraints. I'm not sure if SET NULL or SET DEFAULT can be meaningfully done at all with the current array support, nor exactly what CASCADE means for delete (does it remove the array element or the entire row).