BUG #16342: CREATE TABLE LIKE INCLUDING GENERATED column order issue

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
Thread:
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=#

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Sandeep Thakkar 2020-04-04 03:33:47 Re: Help to Install Postgre SQL
Previous Message Fujii Masao 2020-04-03 17:49:50 Re: [BUG] non archived WAL removed during production crash recovery