Re: Can arrays reference primary keys in CREATE TABLE? - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: Can arrays reference primary keys in CREATE TABLE?
Date
Msg-id 20030523081208.D69228-100000@megazone23.bigpanda.com
Whole thread Raw
In response to Re: Can arrays reference primary keys in CREATE TABLE?  (Oleg Bartunov <oleg@sai.msu.su>)
List pgsql-sql
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).



pgsql-sql by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: libpq program SELECT FOR UPDATE and TIMEOUT or CANCEL REQUEST
Next
From: Jan Wieck
Date:
Subject: Re: Can arrays reference primary keys in CREATE TABLE?