diff --git a/pkg/gossip/client.go b/pkg/gossip/client.go index a279c00a0860..23f376acfdc6 100644 --- a/pkg/gossip/client.go +++ b/pkg/gossip/client.go @@ -259,13 +259,6 @@ func (c *client) handleResponse(ctx context.Context, g *Gossip, reply *Response) "received forward from n%d to n%d (%s); already have active connection, skipping", reply.NodeID, reply.AlternateNodeID, reply.AlternateAddr) } - // We try to resolve the address, but don't actually use the result. - // The certificates (if any) may only be valid for the unresolved - // address. - if _, err := reply.AlternateAddr.Resolve(); err != nil { - return errors.Wrapf(err, "unable to resolve alternate address %s for n%d", - reply.AlternateAddr, reply.AlternateNodeID) - } c.forwardAddr = reply.AlternateAddr return errors.Errorf("received forward from n%d to n%d (%s)", reply.NodeID, reply.AlternateNodeID, reply.AlternateAddr) diff --git a/pkg/sql/catalog/schemaexpr/default_exprs.go b/pkg/sql/catalog/schemaexpr/default_exprs.go index fcbad9631666..045d677885f0 100644 --- a/pkg/sql/catalog/schemaexpr/default_exprs.go +++ b/pkg/sql/catalog/schemaexpr/default_exprs.go @@ -18,6 +18,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/sem/eval" "github.com/cockroachdb/cockroach/pkg/sql/sem/transform" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" + "github.com/cockroachdb/errors" ) // MakeDefaultExprs returns a slice of the default expressions for the slice @@ -71,6 +72,20 @@ func MakeDefaultExprs( if err != nil { return nil, err } + // For "reasons" the CastExpr type check ignores the desired type. That + // means that we can get a result here that is not the right type, and + // we'd need to wrap that in an explicit cast. This is the equivalent of + // an assignment cast we'd insert when writing to the table directly. + if !typedExpr.ResolvedType().Equivalent(col.GetType()) { + if typedExpr, err = tree.TypeCheck(ctx, &tree.CastExpr{ + Expr: typedExpr, + Type: col.GetType(), + SyntaxMode: tree.CastExplicit, + }, semaCtx, col.GetType()); err != nil { + return nil, errors.NewAssertionErrorWithWrappedErrf(err, + "failed to type check the cast of %v to %v", expr, col.GetType()) + } + } if typedExpr, err = txCtx.NormalizeExpr(ctx, evalCtx, typedExpr); err != nil { return nil, err } diff --git a/pkg/sql/logictest/testdata/logic_test/alter_table b/pkg/sql/logictest/testdata/logic_test/alter_table index 823f5b79054e..869ee95df23d 100644 --- a/pkg/sql/logictest/testdata/logic_test/alter_table +++ b/pkg/sql/logictest/testdata/logic_test/alter_table @@ -2751,3 +2751,22 @@ SELECT count(*) from t_with_dropped_index_expr; statement ok RESUME JOB (SELECT job_id FROM crdb_internal.jobs WHERE description LIKE 'ALTER TABLE %t_with_dropped_index_expr DROP COLUMN j CASCADE%' AND status='paused' FETCH FIRST 1 ROWS ONLY); + + +# In 23.1 we added support for default expressions which can be assignment cast +# to the column type. This work introduced a bug whereby the backfill logic +# would not apply the appropriate cast. This test ensures that such tables can +# be backfilled. +subtest add_column_with_default_expression_with_different_type + +statement ok +CREATE TABLE t_93398 (c1 INT); +INSERT INTO t_93398 VALUES (0); + +statement ok +ALTER TABLE t_93398 ADD COLUMN c2 DECIMAL DEFAULT pi(); + +query IT +SELECT * FROM t_93398; +---- +0 3.141592653589793 diff --git a/pkg/sql/logictest/testdata/logic_test/cursor b/pkg/sql/logictest/testdata/logic_test/cursor index 451a07e81dc5..277e7ec90260 100644 --- a/pkg/sql/logictest/testdata/logic_test/cursor +++ b/pkg/sql/logictest/testdata/logic_test/cursor @@ -1,3 +1,6 @@ +statement ok +CLOSE ALL + statement ok CREATE TABLE a (a INT PRIMARY KEY, b INT); INSERT INTO a VALUES (1, 2), (2, 3) @@ -46,6 +49,38 @@ CLOSE foo statement ok COMMIT; +BEGIN; +DECLARE foo CURSOR FOR SELECT * FROM a ORDER BY a + +query II +FETCH 1 foo +---- +1 2 + +statement ok +CLOSE foo + +statement error cursor \"foo\" does not exist +FETCH 2 foo + +statement ok +ROLLBACK; +BEGIN; +DECLARE foo CURSOR FOR SELECT * FROM a ORDER BY a + +query II +FETCH 1 foo +---- +1 2 + +statement ok +CLOSE ALL + +statement error cursor \"foo\" does not exist +FETCH 2 foo + +statement ok +ROLLBACK; statement error cursor \"foo\" does not exist BEGIN; diff --git a/pkg/sql/sql_cursor.go b/pkg/sql/sql_cursor.go index 0d5b35ab44dc..7584b6b2e629 100644 --- a/pkg/sql/sql_cursor.go +++ b/pkg/sql/sql_cursor.go @@ -243,6 +243,9 @@ func (p *planner) CloseCursor(ctx context.Context, n *tree.CloseCursor) (planNod return &delayedNode{ name: n.String(), constructor: func(ctx context.Context, p *planner) (planNode, error) { + if n.All { + return newZeroNode(nil /* columns */), p.sqlCursors.closeAll(false /* errorOnWithHold */) + } return newZeroNode(nil /* columns */), p.sqlCursors.closeCursor(n.Name) }, }, nil