information_schema.view attgenerated

Started by jian healmost 2 years ago4 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

appliessuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t50280
psql -h localhost -U postgres

Built from patchset v3 (message #3), August 17, 2026 at 09:44 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t50280_3 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t50280_3 && git checkout t50280_3

Patchset v3 (message #3) is on t50280_3

Jump to latest
#1jian he
jian.universality@gmail.com

hi.
one minor issue in src/backend/catalog/information_schema.sql
/*
* 6.22
* COLUMNS view
*/
CREATE VIEW columns ....

CAST(CASE WHEN a.attgenerated = '' THEN pg_get_expr(ad.adbin,
ad.adrelid) END AS character_data) AS column_default,
can change to
CAST(CASE WHEN a.attgenerated = '' AND a.atthasdef THEN
pg_get_expr(ad.adbin, ad.adrelid) END AS character_data) AS
column_default,

CAST(CASE WHEN a.attgenerated <> '' THEN 'ALWAYS' ELSE 'NEVER' END AS
character_data) AS is_generated,
can change to
CAST(CASE WHEN a.attgenerated <> '' AND a.atthasdef THEN 'ALWAYS' ELSE
'NEVER' END AS character_data) AS is_generated,

CAST(CASE WHEN a.attgenerated <> '' THEN pg_get_expr(ad.adbin,
ad.adrelid) END AS character_data) AS generation_expression,
can change to
CAST(CASE WHEN a.attgenerated <> '' AND a.atthasdef THEN
pg_get_expr(ad.adbin, ad.adrelid) END AS character_data) AS
generation_expression,

i guess, it will have some minor speed up, also more accurate.

#2Peter Eisentraut
peter_e@gmx.net
In reply to: jian he (#1)
Re: information_schema.view attgenerated

On 16.09.24 06:12, jian he wrote:

hi.
one minor issue in src/backend/catalog/information_schema.sql
/*
* 6.22
* COLUMNS view
*/
CREATE VIEW columns ....

CAST(CASE WHEN a.attgenerated = '' THEN pg_get_expr(ad.adbin,
ad.adrelid) END AS character_data) AS column_default,
can change to
CAST(CASE WHEN a.attgenerated = '' AND a.atthasdef THEN
pg_get_expr(ad.adbin, ad.adrelid) END AS character_data) AS
column_default,

CAST(CASE WHEN a.attgenerated <> '' THEN 'ALWAYS' ELSE 'NEVER' END AS
character_data) AS is_generated,
can change to
CAST(CASE WHEN a.attgenerated <> '' AND a.atthasdef THEN 'ALWAYS' ELSE
'NEVER' END AS character_data) AS is_generated,

CAST(CASE WHEN a.attgenerated <> '' THEN pg_get_expr(ad.adbin,
ad.adrelid) END AS character_data) AS generation_expression,
can change to
CAST(CASE WHEN a.attgenerated <> '' AND a.atthasdef THEN
pg_get_expr(ad.adbin, ad.adrelid) END AS character_data) AS
generation_expression,

i guess, it will have some minor speed up, also more accurate.

I'm having a hard time interpreting this report. Could you be more
clear about what is the existing code, and what is the code you are
proposing as new.?

#3jian he
jian.universality@gmail.com
In reply to: Peter Eisentraut (#2)
Re: information_schema.view attgenerated

On Wed, Sep 18, 2024 at 4:09 PM Peter Eisentraut <peter@eisentraut.org> wrote:

i guess, it will have some minor speed up, also more accurate.

I'm having a hard time interpreting this report. Could you be more
clear about what is the existing code, and what is the code you are
proposing as new.?

sorry for confusion. The changes I propose, also attached.

diff --git a/src/backend/catalog/information_schema.sql
b/src/backend/catalog/information_schema.sql
index c4145131ce..ff8b9305e4 100644
--- a/src/backend/catalog/information_schema.sql
+++ b/src/backend/catalog/information_schema.sql
@@ -688,7 +688,7 @@ CREATE VIEW columns AS
            CAST(c.relname AS sql_identifier) AS table_name,
            CAST(a.attname AS sql_identifier) AS column_name,
            CAST(a.attnum AS cardinal_number) AS ordinal_position,
-           CAST(CASE WHEN a.attgenerated = '' THEN
pg_get_expr(ad.adbin, ad.adrelid) END AS character_data) AS
column_default,
+           CAST(CASE WHEN a.attgenerated = '' AND a.atthasdef THEN
pg_get_expr(ad.adbin, ad.adrelid) END AS character_data) AS
column_default,
            CAST(CASE WHEN a.attnotnull OR (t.typtype = 'd' AND
t.typnotnull) THEN 'NO' ELSE 'YES' END
              AS yes_or_no)
              AS is_nullable,
@@ -777,8 +777,8 @@ CREATE VIEW columns AS
            CAST(seq.seqmin AS character_data) AS identity_minimum,
            CAST(CASE WHEN seq.seqcycle THEN 'YES' ELSE 'NO' END AS
yes_or_no) AS identity_cycle,
-           CAST(CASE WHEN a.attgenerated <> '' THEN 'ALWAYS' ELSE
'NEVER' END AS character_data) AS is_generated,
-           CAST(CASE WHEN a.attgenerated <> '' THEN
pg_get_expr(ad.adbin, ad.adrelid) END AS character_data) AS
generation_expression,
+           CAST(CASE WHEN a.attgenerated <> '' AND a.atthasdef THEN
'ALWAYS' ELSE 'NEVER' END AS character_data) AS is_generated,
+           CAST(CASE WHEN a.attgenerated <> '' AND a.atthasdef THEN
pg_get_expr(ad.adbin, ad.adrelid) END AS character_data) AS
generation_expression,

Attachments:

t50280_3
temp.difftext/x-patch; charset=US-ASCII; name=temp.diffDownload+3-3
#4Peter Eisentraut
peter_e@gmx.net
In reply to: jian he (#3)
Re: information_schema.view attgenerated

On 18.09.24 10:23, jian he wrote:

On Wed, Sep 18, 2024 at 4:09 PM Peter Eisentraut <peter@eisentraut.org> wrote:

i guess, it will have some minor speed up, also more accurate.

I'm having a hard time interpreting this report. Could you be more
clear about what is the existing code, and what is the code you are
proposing as new.?

sorry for confusion. The changes I propose, also attached.

I think this change is not technically wrong, but I think it doesn't
make a difference either way, so I don't see why we should make a change
here.

Show quoted text
diff --git a/src/backend/catalog/information_schema.sql
b/src/backend/catalog/information_schema.sql
index c4145131ce..ff8b9305e4 100644
--- a/src/backend/catalog/information_schema.sql
+++ b/src/backend/catalog/information_schema.sql
@@ -688,7 +688,7 @@ CREATE VIEW columns AS
CAST(c.relname AS sql_identifier) AS table_name,
CAST(a.attname AS sql_identifier) AS column_name,
CAST(a.attnum AS cardinal_number) AS ordinal_position,
-           CAST(CASE WHEN a.attgenerated = '' THEN
pg_get_expr(ad.adbin, ad.adrelid) END AS character_data) AS
column_default,
+           CAST(CASE WHEN a.attgenerated = '' AND a.atthasdef THEN
pg_get_expr(ad.adbin, ad.adrelid) END AS character_data) AS
column_default,
CAST(CASE WHEN a.attnotnull OR (t.typtype = 'd' AND
t.typnotnull) THEN 'NO' ELSE 'YES' END
AS yes_or_no)
AS is_nullable,
@@ -777,8 +777,8 @@ CREATE VIEW columns AS
CAST(seq.seqmin AS character_data) AS identity_minimum,
CAST(CASE WHEN seq.seqcycle THEN 'YES' ELSE 'NO' END AS
yes_or_no) AS identity_cycle,
-           CAST(CASE WHEN a.attgenerated <> '' THEN 'ALWAYS' ELSE
'NEVER' END AS character_data) AS is_generated,
-           CAST(CASE WHEN a.attgenerated <> '' THEN
pg_get_expr(ad.adbin, ad.adrelid) END AS character_data) AS
generation_expression,
+           CAST(CASE WHEN a.attgenerated <> '' AND a.atthasdef THEN
'ALWAYS' ELSE 'NEVER' END AS character_data) AS is_generated,
+           CAST(CASE WHEN a.attgenerated <> '' AND a.atthasdef THEN
pg_get_expr(ad.adbin, ad.adrelid) END AS character_data) AS
generation_expression,