​generated columns in MergeAttributesIntoExisting - Mailing list pgsql-hackers

From Sergei Kornilov
Subject ​generated columns in MergeAttributesIntoExisting
Date
Msg-id 1820191605175217@mail.yandex.ru
Whole thread Raw
List pgsql-hackers
Hello

I found a simple test case:

CREATE TABLE test(id int NOT NULL, gen int GENERATED ALWAYS AS (id + 1) STORED) partition by range (id);
create table test_part_create partition of test for values from ( 0) to (10);
create table test_part_attach (id int NOT NULL, gen int);
alter table test attach partition test_part_attach for values from (10) to (20);

postgres=# \d test_part_create 
                        Table "public.test_part_create"
 Column |  Type   | Collation | Nullable |               Default               
--------+---------+-----------+----------+-------------------------------------
 id     | integer |           | not null | 
 gen    | integer |           |          | generated always as (id + 1) stored
Partition of: test FOR VALUES FROM (0) TO (10)

postgres=# \d test_part_attach 
          Table "public.test_part_attach"
 Column |  Type   | Collation | Nullable | Default 
--------+---------+-----------+----------+---------
 id     | integer |           | not null | 
 gen    | integer |           |          | 
Partition of: test FOR VALUES FROM (10) TO (20)

Both partitions are attached, but alter table attach patition did not check nor enforce a generated column. Same for
tableinheritance stuff. While looking at MergeAttributesIntoExisting in src/backend/commands/tablecmds.c I did not
noticeany special handling or comments for attgenerated. It's an oversight and a bug?
 

Also,
postgres=# alter table test alter COLUMN gen drop expression ;
ERROR:  column "gen" of relation "test_part_attach" is not a stored generated column

Regards, Sergei



pgsql-hackers by date:

Previous
From: Etsuro Fujita
Date:
Subject: Re: Asynchronous Append on postgres_fdw nodes.
Next
From: Gilles Darold
Date:
Subject: Issue with server side statement-level rollback