Re: sub query constraint

From: Dale Sykora <dalen(at)czexan(dot)net>
To: Yudie Pg <yudiepg(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: sub query constraint
Date: 2005-03-30 03:26:54
Message-ID: 424A1C7E.7060600@czexan.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Yudie Pg wrote:
> CREATE OR REPLACE FUNCTION validate_actions_insert() RETRUNS OPAQUE AS '
CREATE OR REPLACE FUNCTION validate_actions_insert() RETURNS OPAQUE AS $$
> DECLARE
> rs RECORD;
>
> BEGIN
> SELECT INTO rs * FROM user_data WHERE name = NEW.user and write_access = 't';
>
> IF NOT FOUND THEN
> RAISE EXCEPTION ''writing access forbidden for user '', NEW.user;
RAISE EXCEPTION 'writing access forbidden for user %', NEW.user;
> END IF;
>
> RETURN NEW;
> END;
> ' LANGUAGE plpgsql;
$$ LANGUAGE plpgsql;
>
> CREATE TRIGGER tg_actions BEFORE INSERT OR UPDATE ON actions
> FOR EACH ROW EXECUTE PROCEDURE validate_actions_insert();

Yugi,
I made a few minor modifications as shown above and the trigger
function works great. I think I'll also use triggers to keep a history
of record changes for auditing.

Thanks,

Dale

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Christopher Browne 2005-03-30 03:33:57 Re: do I need replication or something else?
Previous Message Joshua D. Drake 2005-03-30 02:00:53 Re: Oracle Migration. Don't Care about the Corbomite Maneuver,