Re: Virtual generated columns

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Subject: Re: Virtual generated columns
Date: 2025-01-08 16:25:07
Message-ID: 999d5c67-94f7-4ee8-82ec-09e1fd4bb689@eisentraut.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 03.12.24 15:15, jian he wrote:
> -- check constraints
> CREATE TABLE gtest20 (a int PRIMARY KEY, b int GENERATED ALWAYS AS (a
> * 2) VIRTUAL CHECK (b < 50));
> INSERT INTO gtest20 (a) VALUES (10); -- ok
> INSERT INTO gtest20 (a) VALUES (30); -- violates constraint
>
> ALTER TABLE gtest20 ALTER COLUMN b SET EXPRESSION AS (a * 100); --
> violates constraint
> ALTER TABLE gtest20 ALTER COLUMN b SET EXPRESSION AS (a * 3); -- ok
> -----
> The above content is in src/test/regress/sql/generated_virtual.sql,
> the last two query comments
> seem to conflict with the error message for now.

Fixed the comment in the test in patch v11.

> i add some regress tests for your v10 changes in
> src/backend/commands/statscmds.c.
> please check attached.

Added to patch v11.

> the sql tests,
> "sanity check of system catalog" maybe place it to the end of the sql
> file will have better chance of catching some error.
> for virtual, we can also check attnotnull, atthasdef value.
> like:
> SELECT attrelid, attname, attgenerated FROM pg_attribute WHERE
> attgenerated IN ('v') and (attnotnull or not atthasdef);

I moved the existing check to the bottom, as you suggest.

I don't understand what the purpose of testing attnotnull is. That is
independent of attgenerated, I think.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2025-01-08 16:31:10 Re: ecpg command does not warn COPY ... FROM STDIN;
Previous Message Peter Eisentraut 2025-01-08 16:23:46 Re: Virtual generated columns