pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedListing Triggers
6+ messages / 4 participants
[nested] [flat]
* Listing Triggers
@ 2002-01-30 09:13 Brian McCane <bmccane@mccons.net>
0 siblings, 2 replies; 6+ messages in thread
From: Brian McCane @ 2002-01-30 09:13 UTC (permalink / raw)
To: pgsql-admin
Greetings,
I am sure I have seen this, but I have searched the docs, and
tried to search the archives, which was a definite exercise in futility.
How can I list the triggers on a specific table? I tried the following:
=> select * from pg_trigger where tgargs like '%foo%' ;
ERROR: Unable to identify an operator '~~' for types 'bytea' and 'unknown'
You will have to retype this query using an explicit cast
The reason I ask is because I had a problem the other day. I dropped a
table and the triggers didn't get deleted. I couldn't do anything with
the other table the trigger was on because all of my constraints failed.
I had to go in and manually find and delete the triggers, which was not an
easy task. Finding a couple needles out of 500+ triggers with no good
tools to help me was not fun. HINT: I dumped pg_trigger with oid's to a
file, found the triggers using grep, and then deleted them by oid.
- brian
Wm. Brian McCane | Life is full of doors that won't open
Search http://recall.maxbaud.net/ | when you knock, equally spaced amid those
Usenet http://freenews.maxbaud.net/ | that open when you don't want them to.
Auction http://www.sellit-here.com/ | - Roger Zelazny "Blood of Amber"
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Listing Triggers
@ 2002-01-30 15:57 Tom Lane <tgl@sss.pgh.pa.us>
parent: Brian McCane <bmccane@mccons.net>
1 sibling, 0 replies; 6+ messages in thread
From: Tom Lane @ 2002-01-30 15:57 UTC (permalink / raw)
To: Brian McCane <bmccane@mccons.net>; +Cc: pgsql-admin
Brian McCane <bmccane@mccons.net> writes:
> How can I list the triggers on a specific table?
select * from pg_trigger where tgrelid =
(select oid from pg_class where relname = 'foo');
This table is documented now in the 7.2 documentation; see
http://developer.postgresql.org/docs/postgres/catalog-pg-trigger.html
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Listing Triggers
@ 2002-01-30 16:30 Arguile <arguile@lucentstudios.com>
parent: Brian McCane <bmccane@mccons.net>
1 sibling, 1 reply; 6+ messages in thread
From: Arguile @ 2002-01-30 16:30 UTC (permalink / raw)
To: pgsql-admin
Brian McCane wrote:
> How can I list the triggers on a specific table?
Just as I was typing this I noticed Tom already replied. Just incase you
want to know all triggers referencing the table in addition to those on it
(eg. foreign key constraints).
SELECT t.oid, t.*
FROM pg_trigger t, pg_class c
WHERE where c.oid in (t.tgrelid, t.tgconstrrelid)
AND c.relname = 'foo';
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Listing Triggers
@ 2002-01-30 18:00 Brian McCane <bmccane@mccons.net>
parent: Arguile <arguile@lucentstudios.com>
0 siblings, 2 replies; 6+ messages in thread
From: Brian McCane @ 2002-01-30 18:00 UTC (permalink / raw)
To: pgsql-admin
On Wed, 30 Jan 2002, Arguile wrote:
> Brian McCane wrote:
> > How can I list the triggers on a specific table?
>
> Just as I was typing this I noticed Tom already replied. Just incase you
> want to know all triggers referencing the table in addition to those on it
> (eg. foreign key constraints).
>
> SELECT t.oid, t.*
> FROM pg_trigger t, pg_class c
> WHERE where c.oid in (t.tgrelid, t.tgconstrrelid)
> AND c.relname = 'foo';
>
Thanks Tom and Arguile that definitely helps. Now for my more
pressing, but forgotten question. Shouldn't PostgreSQL have automatically
dropped that trigger when I dropped the table? I dropped and recreated a
small table with a Foreign Key, and each time I do it, I get more triggers
sitting out there that reference the name of the table. This is probably
not a problem if it doesn't reference the correct oid, but I am not sure.
The other problem I had was that I didn't name the constraints that I
created, so I had to delete them from 'pg_trigger' manually, then I had to
update the trigger count in 'pg_class' manually. Would it have worked if
I had changed the name from '<unnamed>' to 'killme' using an update to
'pg_trigger', and then said, "DROP TRIGGER killme ON foo'?
- brian
Wm. Brian McCane | Life is full of doors that won't open
Search http://recall.maxbaud.net/ | when you knock, equally spaced amid those
Usenet http://freenews.maxbaud.net/ | that open when you don't want them to.
Auction http://www.sellit-here.com/ | - Roger Zelazny "Blood of Amber"
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Listing Triggers
@ 2002-01-30 18:26 Tom Lane <tgl@sss.pgh.pa.us>
parent: Brian McCane <bmccane@mccons.net>
1 sibling, 0 replies; 6+ messages in thread
From: Tom Lane @ 2002-01-30 18:26 UTC (permalink / raw)
To: Brian McCane <bmccane@mccons.net>; +Cc: pgsql-admin
Brian McCane <bmccane@mccons.net> writes:
> Thanks Tom and Arguile that definitely helps. Now for my more
> pressing, but forgotten question. Shouldn't PostgreSQL have automatically
> dropped that trigger when I dropped the table?
It should, and it does.
IIRC, there's a bug in some versions of pg_dump that loses the
connection between a foreign-key trigger and the referenced table
(ie, the tgconstrrelid link) when you dump and reload. If you can
exhibit an instance of misbehavior otherwise, I'd like to see it.
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Listing Triggers
@ 2002-01-30 18:31 Stephan Szabo <sszabo@megazone23.bigpanda.com>
parent: Brian McCane <bmccane@mccons.net>
1 sibling, 0 replies; 6+ messages in thread
From: Stephan Szabo @ 2002-01-30 18:31 UTC (permalink / raw)
To: Brian McCane <bmccane@mccons.net>; +Cc: pgsql-admin
On Wed, 30 Jan 2002, Brian McCane wrote:
> On Wed, 30 Jan 2002, Arguile wrote:
>
> > Brian McCane wrote:
> > > How can I list the triggers on a specific table?
> >
> > Just as I was typing this I noticed Tom already replied. Just incase you
> > want to know all triggers referencing the table in addition to those on it
> > (eg. foreign key constraints).
> >
> > SELECT t.oid, t.*
> > FROM pg_trigger t, pg_class c
> > WHERE where c.oid in (t.tgrelid, t.tgconstrrelid)
> > AND c.relname = 'foo';
> >
>
> Thanks Tom and Arguile that definitely helps. Now for my more
> pressing, but forgotten question. Shouldn't PostgreSQL have automatically
> dropped that trigger when I dropped the table? I dropped and recreated a
> small table with a Foreign Key, and each time I do it, I get more triggers
> sitting out there that reference the name of the table. This is probably
> not a problem if it doesn't reference the correct oid, but I am not sure.
If you're using something below (I think) 7.1.3, pg_dump doesn't dump the
information on the other table in the foreign key so the info is lost
after a dump/restore sequence. I was pretty sure this was fixed in 7.1.3
though.
> The other problem I had was that I didn't name the constraints that I
> created, so I had to delete them from 'pg_trigger' manually, then I had to
> update the trigger count in 'pg_class' manually. Would it have worked if
> I had changed the name from '<unnamed>' to 'killme' using an update to
> 'pg_trigger', and then said, "DROP TRIGGER killme ON foo'?
IIRC you need to use the trigger name and not the constraint name for drop
trigger, so if you can find the rows, you should be able to do
DROP TRIGGER "RI_..." ON foo; (the double quotes are required around the
trigger name.
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2002-01-30 18:31 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-01-30 09:13 Listing Triggers Brian McCane <bmccane@mccons.net>
2002-01-30 15:57 ` Tom Lane <tgl@sss.pgh.pa.us>
2002-01-30 16:30 ` Arguile <arguile@lucentstudios.com>
2002-01-30 18:00 ` Brian McCane <bmccane@mccons.net>
2002-01-30 18:26 ` Tom Lane <tgl@sss.pgh.pa.us>
2002-01-30 18:31 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox