From 995febd6447305b0a81f8cecf4432ca677fa5194 Mon Sep 17 00:00:00 2001 From: Daylon Wilkins Date: Tue, 15 Sep 2026 23:02:02 -0700 Subject: [PATCH] Fixes #3328 --- .../information_schema/columns_table.go | 10 ++++++- testing/go/information_schema_test.go | 29 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/server/tables/information_schema/columns_table.go b/server/tables/information_schema/columns_table.go index 5a697a4e7b..fc1c519a4d 100644 --- a/server/tables/information_schema/columns_table.go +++ b/server/tables/information_schema/columns_table.go @@ -149,6 +149,14 @@ func getRowFromColumn(ctx *sql.Context, curOrdPos int, col *sql.Column, catName, datetimePrecision := getDatetimePrecision(col.Type) columnDefault := information_schema.GetColumnDefault(ctx, col.Default) + var generationExpression any + if col.Generated != nil { + if unresolved, isUnresolved := col.Generated.Expr.(*sql.UnresolvedColumnDefault); isUnresolved { + generationExpression = unresolved.String() + } else { + generationExpression = col.Generated.String() + } + } return sql.Row{ catName, // table_catalog @@ -193,7 +201,7 @@ func getRowFromColumn(ctx *sql.Context, curOrdPos int, col *sql.Column, catName, nil, // identity_minimum TODO "NO", // identity_cycle TODO isGenerated, // is_generated - nil, // generation_expression TODO + generationExpression, // generation_expression "YES", // is_updatable } } diff --git a/testing/go/information_schema_test.go b/testing/go/information_schema_test.go index e8e9bb8b6b..26491e5d35 100644 --- a/testing/go/information_schema_test.go +++ b/testing/go/information_schema_test.go @@ -267,6 +267,35 @@ func TestInfoSchemaColumns(t *testing.T) { }, }, }, + { + Name: "generation_expression", + SetUpScript: []string{ + "CREATE TABLE t3328_issue (a INT, b INT GENERATED ALWAYS AS (a + 1) STORED);", + "INSERT INTO t3328_issue (a) VALUES (1);", + "CREATE TABLE t3328 (a INT PRIMARY KEY, s TEXT, b INT GENERATED ALWAYS AS (a + 1) STORED, c TEXT GENERATED ALWAYS AS (upper(s)) STORED, e INT GENERATED ALWAYS AS (a) STORED, f TEXT GENERATED ALWAYS AS (s || ')') STORED);", + }, + Assertions: []ScriptTestAssertion{ + { + Query: "SELECT a, b FROM t3328_issue;", + Expected: []sql.Row{{1, 2}}, + }, + { + Query: "SELECT is_generated, generation_expression, column_default FROM information_schema.columns WHERE table_name = 't3328_issue' AND column_name = 'b';", + Expected: []sql.Row{{"ALWAYS", `("a" + 1)`, nil}}, + }, + { + Query: "SELECT column_name, is_generated, generation_expression, column_default FROM information_schema.columns WHERE table_name = 't3328' ORDER BY ordinal_position;", + Expected: []sql.Row{ + {"a", "NEVER", nil, nil}, + {"s", "NEVER", nil, nil}, + {"b", "ALWAYS", `("a" + 1)`, nil}, + {"c", "ALWAYS", `(upper("s"))`, nil}, + {"e", "ALWAYS", `("a")`, nil}, + {"f", "ALWAYS", `("s" || ')')`, nil}, + }, + }, + }, + }, }) }