Re: [HACKERS] generated columns

From: Erikjan Rijkers <er(at)xs4all(dot)nl>
To: Sergei Kornilov <sk(at)zsrv(dot)org>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Jaime Casanova <jaime(dot)casanova(at)2ndquadrant(dot)com>
Subject: Re: [HACKERS] generated columns
Date: 2018-10-31 07:58:20
Message-ID: 728602640f3ad29c5a355b9ff50377b7@xs4all.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2018-10-30 16:14, Sergei Kornilov wrote:
> Hi
>
> I applied this patch on top 2fe42baf7c1ad96b5f9eb898161e258315298351
> commit and found a bug while adding STORED column:
>
> postgres=# create table test(i int);
> CREATE TABLE
> postgres=# insert into test values (1),(2);
> INSERT 0 2
> postgres=# alter table test add column gen_stored integer GENERATED
> ALWAYS AS ((i * 2)) STORED;
> ALTER TABLE
> postgres=# alter table test add column gen_virt integer GENERATED
> ALWAYS AS ((i * 2));
> ALTER TABLE
> postgres=# table test;
> i | gen_stored | gen_virt
> ---+------------+----------
> 1 | | 2
> 2 | | 4
>
> Virtual columns was calculated on table read and its ok, but stored
> column does not update table data.

This workaround is possible:

update test set i = i where gen_stored is null returning *;
i | gen_stored | gen_virt
---+------------+----------
1 | 2 | 2
2 | 4 | 4
(2 rows)

table test ;
i | gen_stored | gen_virt
---+------------+----------
3 | 6 | 6
4 | 8 | 8
1 | 2 | 2
2 | 4 | 4
(4 rows)

Hm, well, I suppose it's still a bug...

I have also noticed that logical replication isn't possible on tables
with a generated column. That's a shame but I suppsoe that is as
expected.

Erik Rijkers

>
> regards, Sergei

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2018-10-31 08:03:39 Re: ToDo: show size of partitioned table
Previous Message Michael Paquier 2018-10-31 07:55:53 Re: syntax error: VACUUM ANALYZE VERBOSE (PostgreSQL 11 regression)