Skip to content

Commit

Permalink
Merge pull request #133870 from cockroachdb/blathers/backport-release…
Browse files Browse the repository at this point in the history
…-24.3-133850

release-24.3: sql/catalog: fix panic inside sequence expression parsing
  • Loading branch information
rafiss authored Oct 31, 2024
2 parents 1a8dc6a + bba8f76 commit c077ebf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/sql/catalog/seqexpr/sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ func GetSequenceFromFunc(funcExpr *tree.FuncExpr) (*SeqIdentifier, error) {
if len(funcExpr.Exprs) == overload.Types.Length() {
paramTypes, ok := overload.Types.(tree.ParamTypes)
if !ok {
panic(pgerror.Newf(
return nil, pgerror.Newf(
pgcode.InvalidFunctionDefinition,
"%s has invalid argument types", funcExpr.Func.String(),
))
)
}
found = true
for i := 0; i < len(paramTypes); i++ {
Expand All @@ -98,10 +98,10 @@ func GetSequenceFromFunc(funcExpr *tree.FuncExpr) (*SeqIdentifier, error) {
}
}
if !found {
panic(pgerror.New(
return nil, pgerror.New(
pgcode.DatatypeMismatch,
"could not find matching function overload for given arguments",
))
)
}
}
return nil, nil
Expand Down
13 changes: 13 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/create_table
Original file line number Diff line number Diff line change
Expand Up @@ -1097,3 +1097,16 @@ statement ok
SET inject_retry_errors_enabled=false

subtest end


# Addresses a bug where parsing nextval expressions with extra values could end
# end up with a panic when rewriting sequence expressions.
subtest 133399

statement ok
CREATE TABLE v_133399 (c01 INT);

statement error pgcode 42804 could not find matching function overload for given arguments
CREATE TABLE t_133399 AS (SELECT * FROM v_133399 WINDOW window_name AS (ROWS c01 BETWEEN nextval ('abc', 'abc', 'abc') AND c01 PRECEDING));

subtest end

0 comments on commit c077ebf

Please sign in to comment.