Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion server/tables/information_schema/columns_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment thread
Hydrocharged marked this conversation as resolved.
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
Expand Down Expand Up @@ -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
}
}
Expand Down
29 changes: 29 additions & 0 deletions testing/go/information_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
},
},
},
})
}

Expand Down
Loading