Skip to content

Commit

Permalink
tree: block COLLATE "DEFAULT" from working during TypeCheck
Browse files Browse the repository at this point in the history
Release note (sql change): In 21.1, we introduced DEFAULT collation
types, which behave correctly as column definitions. However, getting
COLLATE to work as a value (e.g. `SELECT a::text COLLATE "default"`) is
trickier to make work as it involves a complex change to our type
system. This now returns an unimplemented error pointing to cockroachdb#57255.
  • Loading branch information
otan committed Nov 30, 2020
1 parent 13ce0e8 commit df60e49
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/collatedstring
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,6 @@ SELECT s FROM nocase_strings WHERE s = ('bbb' COLLATE "en-us-u-ks-l""evel2")

statement error at or near "evel2": syntax error
SELECT s FROM nocase_strings WHERE s = ('bbb' COLLATE "en-us-u-ks-l"evel2")

statement error DEFAULT collations are not supported
SELECT 'default collate'::text collate "default"
9 changes: 9 additions & 0 deletions pkg/sql/sem/tree/type_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,15 @@ func (expr *AnnotateTypeExpr) TypeCheck(
func (expr *CollateExpr) TypeCheck(
ctx context.Context, semaCtx *SemaContext, desired *types.T,
) (TypedExpr, error) {
if strings.ToLower(expr.Locale) == DefaultCollationTag {
return nil, errors.WithHint(
unimplemented.NewWithIssuef(
57255,
"DEFAULT collations are not supported",
),
`omit the 'COLLATE "default"' clause in your statement`,
)
}
_, err := language.Parse(expr.Locale)
if err != nil {
return nil, pgerror.Wrapf(err, pgcode.InvalidParameterValue,
Expand Down

0 comments on commit df60e49

Please sign in to comment.