Re: prevent an update from occurring under certain conditions

From: David Saracini <dsaracini(at)yahoo(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: prevent an update from occurring under certain conditions
Date: 2009-03-27 18:21:10
Message-ID: 923403.66000.qm@web82903.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)consumercontact(dot)com> wrote:

> From: Carol Cheung <cacheung(at)consumercontact(dot)com>
> Subject: [NOVICE] prevent an update from occurring under certain conditions
> To: pgsql-novice(at)postgresql(dot)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(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message David Saracini 2009-03-27 18:51:07 Meaning of "$$"
Previous Message Carol Cheung 2009-03-27 15:58:47 prevent an update from occurring under certain conditions