pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
removing duplicated constraints
7+ messages / 2 participants
[nested] [flat]

* removing duplicated constraints
@ 2002-03-02 15:19  Dan Langille <dan@langille.org>
  0 siblings, 1 reply; 7+ messages in thread

From: Dan Langille @ 2002-03-02 15:19 UTC (permalink / raw)
  To: pgsql-admin

I was looking through my database schema and noticed that some foreign key 
declarations were duplicated.  For example, I found this statement 
occurred twice within my DDL:

alter table ports
    add foreign key (category_id)
       references categories (id) on update cascade on delete cascade;

I fixed up the DDL to remove the duplicates.  Then I turned to the 7.2 
PostgreSQL database to examine that situation.  I noticed this 
duplication:

CREATE CONSTRAINT TRIGGER "<unnamed>" AFTER INSERT OR UPDATE ON "ports"  
FROM "categories" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE 
PROCEDURE "RI_FKey_check_ins"
('<unnamed>', 'ports', 'categories', 'UNSPECIFIED', 'category_id', 'id');

CREATE CONSTRAINT TRIGGER "<unnamed>" AFTER INSERT OR UPDATE ON "ports"  
FROM "categories" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE 
PROCEDURE "RI_FKey_check_ins"
('<unnamed>', 'ports', 'categories', 'UNSPECIFIED', 'category_id', 'id');

To my eye, those two contraints are identical.  Some may consider that as 
a bug (i.e postgres allowing a FK to be duplicated).  I see it as a 
feature, which in this case, has been misused.



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: removing duplicated constraints
@ 2002-03-02 17:49  Dan Langille <dan@langille.org>
  parent: Dan Langille <dan@langille.org>
  0 siblings, 2 replies; 7+ messages in thread

From: Dan Langille @ 2002-03-02 17:49 UTC (permalink / raw)
  To: pgsql-admin

On 2 Mar 2002 at 10:19, Dan Langille wrote:

> CREATE CONSTRAINT TRIGGER "<unnamed>" AFTER INSERT OR UPDATE ON "ports" 
> FROM "categories" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE
> PROCEDURE "RI_FKey_check_ins" ('<unnamed>', 'ports', 'categories',
> 'UNSPECIFIED', 'category_id', 'id');
> 
> CREATE CONSTRAINT TRIGGER "<unnamed>" AFTER INSERT OR UPDATE ON "ports" 
> FROM "categories" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE
> PROCEDURE "RI_FKey_check_ins" ('<unnamed>', 'ports', 'categories',
> 'UNSPECIFIED', 'category_id', 'id');

How is an unnamed trigger deleted?  During a dump, I can find information 
such as this:

--
-- TOC Entry ID 211 (OID 998200)
--
-- Name: "RI_ConstraintTrigger_998199" Type: TRIGGER Owner: dan
--

How is that information useful to this situation?
-- 
Dan Langille
The FreeBSD Diary - http://freebsddiary.org/ - practical examples




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: removing duplicated constraints
@ 2002-03-02 19:09  Stephan Szabo <sszabo@megazone23.bigpanda.com>
  parent: Dan Langille <dan@langille.org>
  1 sibling, 0 replies; 7+ messages in thread

From: Stephan Szabo @ 2002-03-02 19:09 UTC (permalink / raw)
  To: Dan Langille <dan@langille.org>; +Cc: pgsql-admin

On Sat, 2 Mar 2002, Dan Langille wrote:

> On 2 Mar 2002 at 10:19, Dan Langille wrote:
>
> > CREATE CONSTRAINT TRIGGER "<unnamed>" AFTER INSERT OR UPDATE ON "ports"
> > FROM "categories" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE
> > PROCEDURE "RI_FKey_check_ins" ('<unnamed>', 'ports', 'categories',
> > 'UNSPECIFIED', 'category_id', 'id');
> >
> > CREATE CONSTRAINT TRIGGER "<unnamed>" AFTER INSERT OR UPDATE ON "ports"
> > FROM "categories" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE
> > PROCEDURE "RI_FKey_check_ins" ('<unnamed>', 'ports', 'categories',
> > 'UNSPECIFIED', 'category_id', 'id');
>
> How is an unnamed trigger deleted?  During a dump, I can find information
> such as this:

The "<unnamed>" is the constraint name given.  It also gets a trigger name
(see system table pg_trigger) which you can use with DROP TRIGGER
(although in the case of the fk constraint triggers you need to double
quote the name).




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: removing duplicated constraints
@ 2002-03-02 21:42  Dan Langille <dan@langille.org>
  parent: Dan Langille <dan@langille.org>
  1 sibling, 2 replies; 7+ messages in thread

From: Dan Langille @ 2002-03-02 21:42 UTC (permalink / raw)
  To: Stephan Szabo <sszabo@megazone23.bigpanda.com>; +Cc: pgsql-admin

On 2 Mar 2002 at 11:09, Stephan Szabo wrote:

> On Sat, 2 Mar 2002, Dan Langille wrote:
> 
> > On 2 Mar 2002 at 10:19, Dan Langille wrote:
> >
> > > CREATE CONSTRAINT TRIGGER "<unnamed>" AFTER INSERT OR UPDATE ON "ports"
> > > FROM "categories" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW
> > > EXECUTE PROCEDURE "RI_FKey_check_ins" ('<unnamed>', 'ports',
> > > 'categories', 'UNSPECIFIED', 'category_id', 'id');
> > >
> > > CREATE CONSTRAINT TRIGGER "<unnamed>" AFTER INSERT OR UPDATE ON "ports"
> > > FROM "categories" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW
> > > EXECUTE PROCEDURE "RI_FKey_check_ins" ('<unnamed>', 'ports',
> > > 'categories', 'UNSPECIFIED', 'category_id', 'id');
> >
> > How is an unnamed trigger deleted?  During a dump, I can find information
> > such as this:
> 
> The "<unnamed>" is the constraint name given.  It also gets a trigger name
> (see system table pg_trigger) which you can use with DROP TRIGGER (although
> in the case of the fk constraint triggers you need to double quote the
> name).

I found the list of duplicate constraints by eyeballing the files I 
created using the methods mentioned in previous post (mainly grep and 
sort).  Then I would search in the original dump file for the the CREATE 
CONSTRAINT statement.  Using the name found there 
(RI_ConstraintTrigger_998199), I did this:

  drop TRIGGER "RI_ConstraintTrigger_998189" on categories;

Making sense?
-- 
Dan Langille
The FreeBSD Diary - http://freebsddiary.org/ - practical examples




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: removing duplicated constraints
@ 2002-03-03 07:42  Stephan Szabo <sszabo@megazone23.bigpanda.com>
  parent: Dan Langille <dan@langille.org>
  1 sibling, 0 replies; 7+ messages in thread

From: Stephan Szabo @ 2002-03-03 07:42 UTC (permalink / raw)
  To: Dan Langille <dan@langille.org>; +Cc: pgsql-admin


> I found the list of duplicate constraints by eyeballing the files I
> created using the methods mentioned in previous post (mainly grep and
> sort).  Then I would search in the original dump file for the the CREATE
> CONSTRAINT statement.  Using the name found there
> (RI_ConstraintTrigger_998199), I did this:
>
>   drop TRIGGER "RI_ConstraintTrigger_998189" on categories;
>
> Making sense?

Well, I'm not sure that you're guaranteed to get the same trigger names
after the restore as the ones in the dump file comments.  You may have to
look in the system table for the actual current trigger name for the
triggers with those arguments.





^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: removing duplicated constraints
@ 2002-03-03 16:11  Dan Langille <dan@langille.org>
  parent: Dan Langille <dan@langille.org>
  1 sibling, 1 reply; 7+ messages in thread

From: Dan Langille @ 2002-03-03 16:11 UTC (permalink / raw)
  To: Stephan Szabo <sszabo@megazone23.bigpanda.com>; +Cc: pgsql-admin

On 2 Mar 2002 at 23:42, Stephan Szabo wrote:

> 
> > I found the list of duplicate constraints by eyeballing the files I
> > created using the methods mentioned in previous post (mainly grep and
> > sort).  Then I would search in the original dump file for the the CREATE
> > CONSTRAINT statement.  Using the name found there
> > (RI_ConstraintTrigger_998199), I did this:
> >
> >   drop TRIGGER "RI_ConstraintTrigger_998189" on categories;
> >
> > Making sense?
> 
> Well, I'm not sure that you're guaranteed to get the same trigger names
> after the restore as the ones in the dump file comments.  You may have to
> look in the system table for the actual current trigger name for the
> triggers with those arguments.

There was no restore.  I did the dump in order to find the duplicates.  
Then used that information to find and remove them.

cheers
-- 
Dan Langille
The FreeBSD Diary - http://freebsddiary.org/ - practical examples




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: removing duplicated constraints
@ 2002-03-03 18:27  Stephan Szabo <sszabo@megazone23.bigpanda.com>
  parent: Dan Langille <dan@langille.org>
  0 siblings, 0 replies; 7+ messages in thread

From: Stephan Szabo @ 2002-03-03 18:27 UTC (permalink / raw)
  To: Dan Langille <dan@langille.org>; +Cc: pgsql-admin

On Sun, 3 Mar 2002, Dan Langille wrote:

> On 2 Mar 2002 at 23:42, Stephan Szabo wrote:
>
> >
> > > I found the list of duplicate constraints by eyeballing the files I
> > > created using the methods mentioned in previous post (mainly grep and
> > > sort).  Then I would search in the original dump file for the the CREATE
> > > CONSTRAINT statement.  Using the name found there
> > > (RI_ConstraintTrigger_998199), I did this:
> > >
> > >   drop TRIGGER "RI_ConstraintTrigger_998189" on categories;
> > >
> > > Making sense?
> >
> > Well, I'm not sure that you're guaranteed to get the same trigger names
> > after the restore as the ones in the dump file comments.  You may have to
> > look in the system table for the actual current trigger name for the
> > triggers with those arguments.
>
> There was no restore.  I did the dump in order to find the duplicates.
> Then used that information to find and remove them.

Then yes, that's all you should need to do.




^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2002-03-03 18:27 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-03-02 15:19 removing duplicated constraints Dan Langille <dan@langille.org>
2002-03-02 17:49 ` Dan Langille <dan@langille.org>
2002-03-02 19:09   ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2002-03-02 21:42   ` Dan Langille <dan@langille.org>
2002-03-03 07:42     ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2002-03-03 16:11     ` Dan Langille <dan@langille.org>
2002-03-03 18:27       ` 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