prevent an update from occurring under certain conditions
prevent an update from occurring under certain conditions
От:
Carol Cheung <cacheung@consumercontact.com>
Дата:
Hi, I'm not sure where to look for information about how to accomplish this: TABLES state: id | state_name | active ----+------------+-------- 1 | Washington | t 2 | Illinois | t county: id | county_name | active | state_id ----+-------------+--------+---------- 1 | King | t | 1 2 | Jefferson | t | 1 I want to prevent an update to set a state's active to false if there are any counties in that state that are active (county.active = true and county.state_id = state.id) Is this possible? Thanks in advance for your help.
Re: prevent an update from occurring under certain conditions
От:
David Saracini <dsaracini@yahoo.com>
Дата:
Hello Carol, Sure... it's possible. You could just write a trigger on the state table to check the county table. If you need help with triggers, here is a couple of links to review: http://www.postgresql.org/docs/8.3/interactive/plpgsql-trigger.html and http://wiki.postgresql.org/wiki/A_Brief_Real-world_Trigger_Example If you still need help, I suggest that you take a stab at it and then post back what you have. Hope this helps. David --- On Fri, 3/27/09, Carol Cheung wrote: > From: Carol Cheung > Subject: [NOVICE] prevent an update from occurring under certain conditions > To: pgsql-novice@postgresql.org > Date: Friday, March 27, 2009, 8:58 AM > Hi, > I'm not sure where to look for information about how to > accomplish this: > > TABLES > state: > id | state_name | active > ----+------------+-------- > 1 | Washington | t > 2 | Illinois | t > > county: > id | county_name | active | state_id > ----+-------------+--------+---------- > 1 | King | t | 1 > 2 | Jefferson | t | 1 > > I want to prevent an update to set a state's active to > false if there are any counties in that state that are > active (county.active = true and county.state_id = state.id) > Is this possible? > > Thanks in advance for your help. > > -- Sent via pgsql-novice mailing list > (pgsql-novice@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-novice