Re: Shouldn't CREATE TABLE LIKE copy the relhasoids property?

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: Shouldn't CREATE TABLE LIKE copy the relhasoids property?
Date: 2015-04-09 15:27:19
Message-ID: 20150409152719.GA4455@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jan 14, 2015 at 07:29:24PM -0500, Tom Lane wrote:
> dst1 doesn't get an OID column:
>
> regression=# create table src1 (f1 int) with oids;
> CREATE TABLE
> regression=# create table dst1 (like src1);
> CREATE TABLE
> regression=# \d+ src1
> Table "public.src1"
> Column | Type | Modifiers | Storage | Stats target | Description
> --------+---------+-----------+---------+--------------+-------------
> f1 | integer | | plain | |
> Has OIDs: yes
>
> regression=# \d+ dst1
> Table "public.dst1"
> Column | Type | Modifiers | Storage | Stats target | Description
> --------+---------+-----------+---------+--------------+-------------
> f1 | integer | | plain | |
>
>
> If you don't find that problematic, how about this case?
>
> regression=# create table src2 (f1 int, primary key(oid)) with oids;
> CREATE TABLE
> regression=# create table dst2 (like src2 including indexes);
> ERROR: column "oid" named in key does not exist

I have developed the attached patch to fix this. The code was basically
confused because setting cxt.hasoids had no effect, and the LIKE
relation was never checked.

The fix is to default cxt.hasoids to false, set it to true if the LIKE
relation has oids, and add WITH OIDS to the CREATE TABLE statement, if
necessary. It also honors WITH/WITHOUT OIDS specified literally in the
CREATE TABLE clause because the first specification is honored, and we
only append WITH OIDS if the LIKE table has oids.

Should this be listed in the release notes as a backward-incompatibility?

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ Everyone has their own god. +

Attachment Content-Type Size
like.diff text/x-diff 1.4 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Stephen Frost 2015-04-09 15:28:31 Re: FPW compression leaks information
Previous Message Heikki Linnakangas 2015-04-09 15:21:57 FPW compression leaks information