Skip to content

Commit 6ce0576

Browse files
committed
builtins: fix pg_collation_for for CITEXT
We missed a spot where we need to unwrap the DOidWrapper corresponding to DCIText. Release note: None
1 parent c40d1e9 commit 6ce0576

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pkg/sql/logictest/testdata/logic_test/citext

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,8 @@ query T
214214
SELECT cast('test'::TEXT AS CITEXT);
215215
----
216216
test
217+
218+
query T
219+
SELECT pg_collation_for('foo'::CITEXT);
220+
----
221+
"default"

pkg/sql/sem/builtins/pg_builtins.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,13 +1013,18 @@ var pgBuiltins = map[string]builtinDefinition{
10131013
Types: tree.ParamTypes{{Name: "str", Typ: types.AnyElement}},
10141014
ReturnType: tree.FixedReturnType(types.String),
10151015
Fn: func(_ context.Context, _ *eval.Context, args tree.Datums) (tree.Datum, error) {
1016+
d := args[0]
10161017
var collation string
1017-
switch t := args[0].(type) {
1018+
switch t := d.(type) {
10181019
case *tree.DString:
10191020
collation = "default"
10201021
case *tree.DCollatedString:
10211022
collation = t.Locale
10221023
default:
1024+
if w, ok := d.(*tree.DOidWrapper); ok && w.Oid == oidext.T_citext {
1025+
collation = "default"
1026+
break
1027+
}
10231028
return tree.DNull, pgerror.Newf(pgcode.DatatypeMismatch,
10241029
"collations are not supported by type: %s", t.ResolvedType())
10251030
}

0 commit comments

Comments
 (0)