public inbox for [email protected]  
help / color / mirror / Atom feed
From: Peter Eisentraut <[email protected]>
To: jian he <[email protected]>
Cc: pgsql-hackers <[email protected]>
Cc: Dean Rasheed <[email protected]>
Subject: Re: Virtual generated columns
Date: Wed, 8 Jan 2025 17:25:07 +0100
Message-ID: <[email protected]> (raw)
In-Reply-To: <CACJufxEeUfpUoFng=0Pm0-cJ4rwyBJCv4x_FXmkYqozWB7uvFQ@mail.gmail.com>
References: <[email protected]>
	<[email protected]>
	<[email protected]>
	<CAEZATCV=RX0M58-uqSR6tFjwQAFnEcx3hvW-9ZZfRQJLg5LzRw@mail.gmail.com>
	<[email protected]>
	<CAEZATCU3q=znAL7X1aSxuMpjfSyB1cT5j398HPb9ix9ci_HUqA@mail.gmail.com>
	<[email protected]>
	<CAEZATCVLfMzNwT1J0bnvtv6YbmNSN9QSXb+1QSGyX6vK4q67Ow@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<CACJufxF8fmM=Dbm4pDFuV_nKGz2-No0k4YifhrF3-rjXTWJM3w@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<CACJufxEeUfpUoFng=0Pm0-cJ4rwyBJCv4x_FXmkYqozWB7uvFQ@mail.gmail.com>

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.







view thread (75+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Virtual generated columns
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox