Question Regarding DELETE FROM ONLY - Mailing list pgsql-general

From Terry Lee Tucker
Subject Question Regarding DELETE FROM ONLY
Date
Msg-id 200605290840.43506.terry@esc1.com
Whole thread Raw
Responses Re: Question Regarding DELETE FROM ONLY  (Michael Fuhr <mike@fuhr.org>)
List pgsql-general
Hello List:

Please observe the following example that reproduces my problem:

CREATE TABLE ptable (code VARCHAR) WITHOUT OIDS;
CREATE TABLE

CREATE TABLE ctable (code VARCHAR, name VARCHAR)
    INHERITS (ptable) WITHOUT OIDS;
NOTICE:  merging column "code" with inherited definition
CREATE TABLE

INSERT INTO ctable (code, name) VALUES ('code_one', 'Code One');
rnd=# SELECT * FROM ptable;
   code
----------
 code_one
(1 row)

rnd=# SELECT * FROM ctable;
        code   |   name
---------------+----------
 code_one | Code One
(1 row)

DELETE FROM ONLY ctable WHERE code ~* 'code_one';

rnd=# SELECT * FROM ptable;
 code
------
(0 rows)

The record in ctable AND the record in ptable are both deleted even though I
specified "ONLY ctable" in the delete phrase. Why is this happening? The two
tables in this example represent a greatly simplified version of what I'm
doing in developing an application and if "ONLY" doesn't work then I've got a
big problem. Have I misunderstood inheritance altogether?

TIA...

rnd=# select version();
                                                   version
--------------------------------------------------------------------------------------------------------------
 PostgreSQL 7.4.6 on i686-redhat-linux-gnu, compiled by GCC gcc (GCC) 3.2.3
20030502 (Red Hat Linux 3.2.3-49)
(1 row)


pgsql-general by date:

Previous
From: Eci Souji
Date:
Subject: Re: DB structure for logically similar objects in different
Next
From: "Tomi NA"
Date:
Subject: Re: Best open source tool for database design / ERDs?