Question Regarding DELETE FROM ONLY

From: Terry Lee Tucker <terry(at)esc1(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Question Regarding DELETE FROM ONLY
Date: 2006-05-29 12:40:43
Message-ID: 200605290840.43506.terry@esc1.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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)

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tomi NA 2006-05-29 12:43:19 Re: Best open source tool for database design / ERDs?
Previous Message Eci Souji 2006-05-29 12:18:16 Re: DB structure for logically similar objects in different