Thread: Problem with FKEYS

Problem with FKEYS

From
Rajesh Kumar Mallah
Date:

How come pgsql7.3.4  Was allowing me to delete the master record while
referencing records were present in slave table?

The problem was detected when the database was migrated to 7.4 and
deletions were being refused.

Regards
Mallah


tradein_clients=# \d user_services
   Table "public.user_services"
   Column   |  Type   | Modifiers
------------+---------+-----------
 userid     | integer | not null
 service_id | integer | not null
Indexes: user_services_key unique btree (userid, service_id),
         user_services_service_id btree (service_id)
Foreign Key constraints: $2 FOREIGN KEY (userid) REFERENCES users(userid) ON UPDATE NO ACTION ON DELETE NO ACTION,
                         $1 FOREIGN KEY (service_id) REFERENCES services_master(service_id) ON
                UPDATE NO ACTION ON DELETE NO ACTION

tradein_clients=# SELECT * from user_services where userid=276720 ;
 userid | service_id
--------+------------
 276720 |          1
(1 row)

tradein_clients=# begin work;DELETE from users where userid=276720 ;rollback;
BEGIN
DELETE 1
ROLLBACK
tradein_clients=# SELECT version();
                           version
-------------------------------------------------------------
 PostgreSQL 7.3.4 on i686-pc-linux-gnu, compiled by GCC 2.96
(1 row)

tradein_clients=#


Re: Problem with FKEYS

From
Tom Lane
Date:
Rajesh Kumar Mallah <mallah@trade-india.com> writes:
> How come pgsql7.3.4  Was allowing me to delete the master record while
> referencing records were present in slave table?

The only explanation I can think of is that the referencing row shown as
being in user_services was actually in a child table --- foreign keys
don't work in inheritance hierarchies at the moment.

If that's not it, can you provide a self-contained example?

            regards, tom lane

Re: Problem with FKEYS

From
Rajesh Kumar Mallah
Date:
Tom Lane wrote:

  Rajesh Kumar Mallah <mallah@trade-india.com> writes:


    How come pgsql7.3.4  Was allowing me to delete the master record while
referencing records were present in slave table?



The only explanation I can think of is that the referencing row shown as
being in user_services was actually in a child table --- foreign keys
don't work in inheritance hierarchies at the moment.


No, That is not the case , they are plain tables.




If that's not it, can you provide a self-contained example?

Could not replicate it with newly created tables. Only those set of
table
has the problem. I am ready to provide any required info .

Regds
Mallah.




            regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

               http://archives.postgresql.org