PostgreSQL Bugs

Collected from the PG bugs email list.

Bug ID16342
PG Version12.2
OSDebian Buster
Opened2020-04-03 23:50:51+00
Reported byEthan Waldo
StatusNew

Body of first available message related to this bug follows.

The following bug has been logged on the website:

Bug reference:      16342
Logged by:          Ethan Waldo
Email address:      (redacted)
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=#

Messages

DateAuthorSubject
2020-04-03 23:50:51+00PG Bug reporting formBUG #16342: CREATE TABLE LIKE INCLUDING GENERATED column order issue
2020-04-05 11:28:20+00Peter EisentrautRe: BUG #16342: CREATE TABLE LIKE INCLUDING GENERATED column order issue
2020-04-05 15:26:36+00Tom LaneRe: BUG #16342: CREATE TABLE LIKE INCLUDING GENERATED column order issue
2020-04-09 14:48:29+00Peter EisentrautRe: BUG #16342: CREATE TABLE LIKE INCLUDING GENERATED column order issue
2020-04-09 14:55:25+00Ethan WaldoRE: BUG #16342: CREATE TABLE LIKE INCLUDING GENERATED column order issue