Re: TRIGGER TRUNCATE -- CASCADE or RESTRICT

From: Melvin Davidson <melvin6925(at)gmail(dot)com>
To: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
Cc: "Andreas Ulbrich *EXTERN*" <andreas(dot)ulbrich(at)matheversum(dot)de>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: TRIGGER TRUNCATE -- CASCADE or RESTRICT
Date: 2015-06-02 14:20:54
Message-ID: CANu8FixUUeAc5zNyBjA5bM-gVJsBU2+rS7MBsadp1fWMjMiB_g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

You can use the following to list the triggers and see what functions they
call. Then you can check pg_proc to see how TRUNCATE is used in prosrc.

SELECT c.relname,
t.tgname,
p.proname AS function_called,
t.tgconstraint AS is_constraint,
CASE WHEN t.tgconstrrelid > 0
THEN (SELECT relname
FROM pg_class
WHERE oid = t.tgconstrrelid)
ELSE ''
END AS constr_tbl,
t.tgenabled
FROM pg_trigger t
INNER JOIN pg_proc p ON ( p.oid = t.tgfoid)
INNER JOIN pg_class c ON (c.oid = t.tgrelid)
WHERE tgname NOT LIKE 'pg_%'
AND tgname NOT LIKE 'RI_%' -- < comment out to see constraints
-- AND t.tgenabled = FALSE
ORDER BY 1;

On Tue, Jun 2, 2015 at 5:31 AM, Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
wrote:

> Andreas Ulbrich wrote:
> > I'm in a handle for a trigger for TRUNCATE. Is it possible to find out
> > whether the TRUNCATE TABLE ist called with CASCADE?
>
> I don't think there is.
>
> But you can find out the table where the trigger is defined and examine
> if any foreign key constraints are referring to it.
>
> If yes, then the trigger was called with CASCADE.
> If no, it might have been called either way, but the effect would be the
> same.
>
> Yours,
> Laurenz Albe
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

--
*Melvin Davidson*
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2015-06-02 14:22:24 Re: Python 3.2 XP64 and Numpy...
Previous Message Ivann Ruiz 2015-06-02 14:14:48 Automatic Failover