From: | Jan Wieck <JanWieck(at)Yahoo(dot)com> |
---|---|
To: | Luis Sousa <llsousa(at)ualg(dot)pt> |
Cc: | Richard Huxton <dev(at)archonet(dot)com>, Filipe Bonjour <fbonjour(at)urbanet(dot)ch>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Can arrays reference primary keys in CREATE TABLE? |
Date: | 2003-05-22 10:56:27 |
Message-ID: | 3ECCACDB.6030008@Yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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
and loop through the arrays - but it has to select all of them for
update (resulting effectively in a full table lock, bye bye concurrency)
because otherwise it'll see an older snapshot ignoring concurrent
transactions.
What you can do, if you don't want or can't give up the array in the
first place, set up another table that holds the primary key and the
arrays single values in rows. This table is managed by INSERT, UPDATE
and DELETE triggers of the table with the array. Now put the foreign key
constraint on that table instead and you have the desired behaviour with
real referential integrity.
Jan
--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #
From | Date | Subject | |
---|---|---|---|
Next Message | Christoph Haller | 2003-05-22 12:51:17 | Re: Testing castability of text to numeric |
Previous Message | Luis Sousa | 2003-05-22 09:10:15 | Re: Can arrays reference primary keys in CREATE TABLE? |