Re: prevent an update from occurring under certain conditions - Mailing list pgsql-novice

From David Saracini
Subject Re: prevent an update from occurring under certain conditions
Date
Msg-id 923403.66000.qm@web82903.mail.mud.yahoo.com
Whole thread Raw
In response to prevent an update from occurring under certain conditions  (Carol Cheung <cacheung@consumercontact.com>)
List pgsql-novice
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 <cacheung@consumercontact.com> wrote:

> From: Carol Cheung <cacheung@consumercontact.com>
> 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

pgsql-novice by date:

Previous
From: Carol Cheung
Date:
Subject: prevent an update from occurring under certain conditions
Next
From: David Saracini
Date:
Subject: Meaning of "$$"