Skip site navigation (1) Skip section navigation (2)

ALTER TABLE parent SET WITHOUT OIDS and the oid column

From: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: ALTER TABLE parent SET WITHOUT OIDS and the oid column
Date: 2016-12-26 10:06:59
Message-ID: cb13cfe7-a48c-5720-c383-bb843ab28298@lab.ntt.co.jp (view raw, whole thread or download thread mbox)
Thread:
Lists: pgsql-hackers
I suspect the following is a bug:

create table foo (a int) with oids;
CREATE TABLE
create table bar (a int);
CREATE TABLE
alter table bar inherit foo;
ERROR:  table "bar" without OIDs cannot inherit from table "foo" with OIDs

alter table bar set with oids;
ALTER TABLE
alter table bar inherit foo;
ALTER TABLE

alter table foo set without oids;
ERROR:  relation 16551 has non-inherited attribute "oid"

Because:

select attinhcount from pg_attribute where attrelid = 'bar'::regclass and
attname = 'oid';
 attinhcount
-------------
           0
(1 row)

Which also means "oid" can be safely dropped from bar breaking the
invariant that if the parent table has oid column, its child tables must too:

alter table bar drop oid;  -- or, alter table bar set without oids;
ALTER TABLE

Attached patches modifies MergeAttributesIntoExisting() such that we
increment attinhcount not only for user attributes, but also for the oid
system column if one exists.

Thoughts?

Thanks,
Amit

Attachment: alter-table-inherit-oid-column-bug-1.patch
Description: text/x-diff (2.9 KB)

Responses

pgsql-hackers by date

Next:From: Amit LangoteDate: 2016-12-26 10:11:42
Subject: Re: ALTER TABLE parent SET WITHOUT OIDS and the oid column
Previous:From: Pavel StehuleDate: 2016-12-26 10:02:12
Subject: Re: proposal: session server side variables

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group