Lists: | pgsql-bugs |
---|
From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
---|---|
To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
Cc: | ewaldo(at)healthetechs(dot)com |
Subject: | BUG #16342: CREATE TABLE LIKE INCLUDING GENERATED column order issue |
Date: | 2020-04-03 23:50:51 |
Message-ID: | 16342-50008a509308f4ca@postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-bugs |
The following bug has been logged on the website:
Bug reference: 16342
Logged by: Ethan Waldo
Email address: ewaldo(at)healthetechs(dot)com
PostgreSQL version: 12.2
Operating system: Debian Buster
Description:
CREATE TABLE succeeds when using generated columns and it doesn't matter
what order they are in. When CREATE TABLE LIKE INCLUDING GENERATED is used,
it only works if the source column was created first in the original
table.
postgres=# CREATE TABLE test (
funds float GENERATED ALWAYS AS (cast(funds_t AS double precision))
STORED,
funds_t text,
id bigserial not null
);
CREATE TABLE
postgres=# CREATE TABLE IF NOT EXISTS test_temp (LIKE test INCLUDING
GENERATED);
ERROR: XX000: unexpected varattno 3 in expression to be mapped
LOCATION: map_variable_attnos_mutator, rewriteManip.c:1255
postgres=# DROP TABLE test;
DROP TABLE
# Works with funds and funds_t order flipped
postgres=# CREATE TABLE test (
funds_t text,
funds float GENERATED ALWAYS AS (cast(funds_t AS double precision))
STORED,
id bigserial not null
);
CREATE TABLE
postgres=# CREATE TABLE IF NOT EXISTS test_temp (LIKE test INCLUDING
GENERATED);
CREATE TABLE
postgres=#
From: | Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> |
---|---|
To: | ewaldo(at)healthetechs(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
Subject: | Re: BUG #16342: CREATE TABLE LIKE INCLUDING GENERATED column order issue |
Date: | 2020-04-05 11:28:20 |
Message-ID: | db920c8a-063e-a320-c5e8-096f0eedc154@2ndquadrant.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-bugs |
On 2020-04-04 01:50, PG Bug reporting form wrote:
> postgres=# CREATE TABLE test (
> funds float GENERATED ALWAYS AS (cast(funds_t AS double precision))
> STORED,
> funds_t text,
> id bigserial not null
> );
> CREATE TABLE
>
> postgres=# CREATE TABLE IF NOT EXISTS test_temp (LIKE test INCLUDING
> GENERATED);
> ERROR: XX000: unexpected varattno 3 in expression to be mapped
> LOCATION: map_variable_attnos_mutator, rewriteManip.c:1255
Confirmed. Attached is a patch to fix it. Thanks for the report!
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachment | Content-Type | Size |
---|---|---|
0001-Fix-CREATE-TABLE-LIKE-INCLUDING-GENERATED-column-ord.patch | text/plain | 8.1 KB |
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> |
Cc: | ewaldo(at)healthetechs(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
Subject: | Re: BUG #16342: CREATE TABLE LIKE INCLUDING GENERATED column order issue |
Date: | 2020-04-05 15:26:36 |
Message-ID: | 10837.1586100396@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-bugs |
Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> writes:
> Confirmed. Attached is a patch to fix it. Thanks for the report!
LGTM. Perhaps extend the comment block just above, adding something
like "We must fill the attmap now so it can be used to process
GENERATED default expressions in the per-column loop."
regards, tom lane
From: | Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | ewaldo(at)healthetechs(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
Subject: | Re: BUG #16342: CREATE TABLE LIKE INCLUDING GENERATED column order issue |
Date: | 2020-04-09 14:48:29 |
Message-ID: | dff50573-9092-4ad0-8fb6-a1f01e736f13@2ndquadrant.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-bugs |
On 2020-04-05 17:26, Tom Lane wrote:
> Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> writes:
>> Confirmed. Attached is a patch to fix it. Thanks for the report!
>
> LGTM. Perhaps extend the comment block just above, adding something
> like "We must fill the attmap now so it can be used to process
> GENERATED default expressions in the per-column loop."
Committed with that.
Ethan, this will be in the next minor release of PostgreSQL 12.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From: | Ethan Waldo <ewaldo(at)healthetechs(dot)com> |
---|---|
To: | Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org> |
Subject: | RE: BUG #16342: CREATE TABLE LIKE INCLUDING GENERATED column order issue |
Date: | 2020-04-09 14:55:25 |
Message-ID: | DM5PR0601MB3750DE8B9595D2E9848920C9B1C10@DM5PR0601MB3750.namprd06.prod.outlook.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-bugs |
Thank you for such a timely response and the best and most fully featured database software money can't buy!
Sent from my Samsung Galaxy smartphone.
-------- Original message --------
From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Date: 4/9/20 10:48 AM (GMT-05:00)
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Ethan Waldo <ewaldo(at)healthetechs(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16342: CREATE TABLE LIKE INCLUDING GENERATED column order issue
On 2020-04-05 17:26, Tom Lane wrote:
> Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> writes:
>> Confirmed. Attached is a patch to fix it. Thanks for the report!
>
> LGTM. Perhaps extend the comment block just above, adding something
> like "We must fill the attmap now so it can be used to process
> GENERATED default expressions in the per-column loop."
Committed with that.
Ethan, this will be in the next minor release of PostgreSQL 12.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services