Skip to content

Commit 53017c1

Browse files
committed
scbuild: change parameter type of helper functions
This makes it easier to remember to format the name correctly. This also adjusts an error message to be slightly more accurate. Release note: None
1 parent cae45b3 commit 53017c1

11 files changed

+29
-20
lines changed

pkg/sql/alter_table.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ func applyColumnMutation(
986986
}
987987
return pgerror.Newf(
988988
pgcode.Syntax,
989-
"computed column %q cannot also have a DEFAULT expression",
989+
"computed column %q cannot also have a DEFAULT or ON UPDATE expression",
990990
col.GetName())
991991
}
992992
if err := updateNonComputedColExpr(
@@ -1005,6 +1005,12 @@ func applyColumnMutation(
10051005
}
10061006

10071007
case *tree.AlterTableSetOnUpdate:
1008+
if col.IsComputed() {
1009+
return pgerror.Newf(
1010+
pgcode.Syntax,
1011+
"computed column %q cannot also have a DEFAULT or ON UPDATE expression",
1012+
col.GetName())
1013+
}
10081014
// We want to reject uses of ON UPDATE where there is also a foreign key ON
10091015
// UPDATE.
10101016
for _, fk := range tableDesc.OutboundFKs {

pkg/sql/catalog/tabledesc/structured_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ func TestRemoveDefaultExprFromComputedColumn(t *testing.T) {
963963
defer srv.Stopper().Stop(context.Background())
964964
tdb := sqlutils.MakeSQLRunner(sqlDB)
965965

966-
const expectedErrRE = `.*: computed column \"b\" cannot also have a DEFAULT expression`
966+
const expectedErrRE = `.*: computed column \"b\" cannot also have a DEFAULT or ON UPDATE expression`
967967
// Create a table with a computed column.
968968
tdb.Exec(t, `CREATE DATABASE t`)
969969
tdb.Exec(t, `CREATE TABLE t.tbl (a INT PRIMARY KEY, b INT AS (1) STORED)`)

pkg/sql/logictest/testdata/logic_test/computed

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ SELECT * FROM t69327
13191319
f f
13201320

13211321
# Regression test for #72881. Computed columns can't have a DEFAULT expr.
1322-
statement error pgcode 42601 computed column "v" cannot also have a DEFAULT expression
1322+
statement error pgcode 42601 computed column "v" cannot also have a DEFAULT or ON UPDATE expression
13231323
ALTER TABLE t69327 ALTER COLUMN v SET DEFAULT 'foo'
13241324

13251325
# Regression test for #69665.Computed columns should be evaluated after
@@ -1379,10 +1379,13 @@ CREATE TABLE foooooo (
13791379
gen INT AS (x + y) STORED
13801380
);
13811381

1382-
statement error pgcode 42601 computed column "gen" cannot also have a DEFAULT expression
1382+
statement error pgcode 42601 computed column "gen" cannot also have a DEFAULT or ON UPDATE expression
13831383
ALTER TABLE foooooo ALTER COLUMN gen SET DEFAULT 1;
13841384

1385-
statement error pgcode 42601 computed column "gen" cannot also have a DEFAULT expression
1385+
statement error pgcode 42601 computed column "gen" cannot also have a DEFAULT or ON UPDATE expression
1386+
ALTER TABLE foooooo ALTER COLUMN gen SET ON UPDATE 1;
1387+
1388+
statement error pgcode 42601 computed column "gen" cannot also have a DEFAULT or ON UPDATE expression
13861389
ALTER TABLE foooooo ALTER COLUMN gen SET DEFAULT NULL;
13871390

13881391
statement error pgcode 42601 column "gen" of relation "foooooo" is a computed column

pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_alter_column_drop_not_null.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func alterTableDropNotNull(
2323
alterColumnPreChecks(b, tn, tbl, t.Column)
2424
columnID := getColumnIDFromColumnName(b, tbl.TableID, t.Column, true /*required */)
2525
// Block alters on system columns.
26-
panicIfSystemColumn(mustRetrieveColumnElem(b, tbl.TableID, columnID), t.Column.String())
26+
panicIfSystemColumn(mustRetrieveColumnElem(b, tbl.TableID, columnID), t.Column)
2727
// Ensure that this column is not in the primary indexes key.
2828
primaryIdx := getLatestPrimaryIndex(b, tbl.TableID)
2929
idxColumns := mustRetrieveIndexColumnElements(b, tbl.TableID, primaryIdx.IndexID)

pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_alter_column_set_default.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ func alterTableSetDefault(
3434
colType := mustRetrieveColumnTypeElem(b, tbl.TableID, colID)
3535

3636
// Block alters on system columns.
37-
panicIfSystemColumn(col, t.Column.String())
37+
panicIfSystemColumn(col, t.Column)
3838

3939
// Block disallowed operations on computed columns.
40-
panicIfComputedColumn(b, tn.ObjectName, colType, t.Column.String(), t.Default)
40+
panicIfComputedColumn(b, tn.ObjectName, colType, t.Column, t.Default)
4141

4242
// For DROP DEFAULT.
4343
if t.Default == nil {
@@ -148,7 +148,7 @@ func sanitizeColumnExpression(
148148

149149
// panicIfComputedColumn blocks disallowed operations on computed columns.
150150
func panicIfComputedColumn(
151-
b BuildCtx, tn tree.Name, col *scpb.ColumnType, colName string, def tree.Expr,
151+
b BuildCtx, tn tree.Name, col *scpb.ColumnType, colName tree.Name, def tree.Expr,
152152
) {
153153
computeExpr := retrieveColumnComputeExpression(b, col.TableID, col.ColumnID)
154154
// Block setting a column default if the column is computed.
@@ -158,12 +158,12 @@ func panicIfComputedColumn(
158158
panic(pgerror.Newf(
159159
pgcode.Syntax,
160160
"column %q of relation %q is a computed column",
161-
colName,
161+
tree.ErrString(&colName),
162162
tn))
163163
}
164164
panic(pgerror.Newf(
165165
pgcode.Syntax,
166-
"computed column %q cannot also have a DEFAULT expression",
167-
colName))
166+
"computed column %q cannot also have a DEFAULT or ON UPDATE expression",
167+
tree.ErrString(&colName)))
168168
}
169169
}

pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_alter_column_set_not_null.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func alterTableSetNotNull(
2525
return
2626
}
2727
// Block alters on system columns.
28-
panicIfSystemColumn(mustRetrieveColumnElem(b, tbl.TableID, columnID), t.Column.String())
28+
panicIfSystemColumn(mustRetrieveColumnElem(b, tbl.TableID, columnID), t.Column)
2929
b.Add(&scpb.ColumnNotNull{
3030
TableID: tbl.TableID,
3131
ColumnID: columnID,

pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_alter_column_set_on_update.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ func alterTableSetOnUpdate(
2424
colType := mustRetrieveColumnTypeElem(b, tbl.TableID, colID)
2525

2626
// Block alters on system columns.
27-
panicIfSystemColumn(col, t.Column.String())
27+
panicIfSystemColumn(col, t.Column)
2828

2929
// Block disallowed operations on computed columns.
30-
panicIfComputedColumn(b, tn.ObjectName, colType, t.Column.String(), t.Expr)
30+
panicIfComputedColumn(b, tn.ObjectName, colType, t.Column, t.Expr)
3131

3232
// For DROP ON UPDATE.
3333
if t.Expr == nil {

pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_alter_column_type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func alterTableAlterColumnType(
4242
) {
4343
colID := getColumnIDFromColumnName(b, tbl.TableID, t.Column, true /* required */)
4444
col := mustRetrieveColumnElem(b, tbl.TableID, colID)
45-
panicIfSystemColumn(col, t.Column.String())
45+
panicIfSystemColumn(col, t.Column)
4646

4747
// Setup for the new type ahead of any checking. As we need its resolved type
4848
// for the checks.

pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_drop_column.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func resolveColumnForDropColumn(
109109
return nil, nil, true
110110
}
111111
// Block drops on system columns.
112-
panicIfSystemColumn(col, n.Column.String())
112+
panicIfSystemColumn(col, n.Column)
113113
return col, elts, false
114114
}
115115

pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_rename_column.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func renameColumnChecks(b BuildCtx, col *scpb.Column, oldName, newName tree.Name
7171
}
7272

7373
// Block renaming of system columns.
74-
panicIfSystemColumn(col, oldName.String())
74+
panicIfSystemColumn(col, oldName)
7575

7676
// Block renaming of shard columns.
7777
if isShardColumn(b, col) {

0 commit comments

Comments
 (0)