BUG #16342: CREATE TABLE LIKE INCLUDING GENERATED column order issue - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #16342: CREATE TABLE LIKE INCLUDING GENERATED column order issue
Date
Msg-id 16342-50008a509308f4ca@postgresql.org
Whole thread Raw
Responses Re: BUG #16342: CREATE TABLE LIKE INCLUDING GENERATED column orderissue
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      16342
Logged by:          Ethan Waldo
Email address:      ewaldo@healthetechs.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=#


pgsql-bugs by date:

Previous
From: Fujii Masao
Date:
Subject: Re: [BUG] non archived WAL removed during production crash recovery
Next
From: Sandeep Thakkar
Date:
Subject: Re: Help to Install Postgre SQL