pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Scott Marlowe <smarlowe@qwest.net>
To: Pradeepkumar, Pyatalo (IE10) <Pradeepkumar.Pyatalo@honeywell.com>
Cc: pgsql-novice@postgresql.org
Subject: Re: Help on triggers
Date: Mon, 02 Aug 2004 02:19:03 -0600
Message-ID: <1091434743.27166.19.camel@localhost.localdomain> (raw)
In-Reply-To: <77ED2BF75D59D1439F90412CC5B109740FA2CD4D@ie10-sahara.hiso.honeywell.com>
References: <77ED2BF75D59D1439F90412CC5B109740FA2CD4D@ie10-sahara.hiso.honeywell.com>

On Sun, 2004-08-01 at 23:27, Pradeepkumar, Pyatalo (IE10) wrote:
> Hi all,
> 
> I have 2 tables - table1 and table2. Both the tables are related to each
> other. I have written triggers so that if a tuple is inserted into table1,
> corresponding values will be inserted into table2. and if a tuple is deleted
> from table1 then corresponding tuples are deleted from table2 also. The
> delete trigger works fine sometimes and other times it gives the following
> error.....
> 
> delete from table1 where pointid=30;
> ERROR: update or delete on "table1" violates foreign key constraint "$2" on
> "table2"
> DETAIL: key (pointid) =30 is still referenced from table "pointattributes".
> 
> I am doing an application in C. I have written a C-function using libpq API
> to delete a tuple from table1. that is I pass a parameter to the function
> and it has to delete the tuple whose primarykey value= parameter and also
> delete correspoding tuples from table2(due to the trigger). so i have formed
> a simple delete command on table2in the C-function. When i compile the
> application it gives the same error:
> 
> is there anyone who can explain why this is happening. I had posted this
> query 2 days back...dint get any reply. Please help me out with this.

Using foreign keys, you should be able to just set the relation to
cascade and have the dependent rows deleted automagically.




view thread (2+ messages)

Message-ID: <1091434743.27166.19.camel@localhost.localdomain>
Permalink:  ../1091434743.27166.19.camel@localhost.localdomain/
Also on:    postgresql.org/message-id/1091434743.27166.19.camel@localhost.localdomain

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: smarlowe@qwest.net, Pradeepkumar.Pyatalo@honeywell.com, pgsql-novice@postgresql.org
  Subject: Re: Help on triggers
  In-Reply-To: <1091434743.27166.19.camel@localhost.localdomain>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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