diff --git a/docs/generated/sql/functions.md b/docs/generated/sql/functions.md
index 596f1f12ad3e..31147c9f2f1c 100644
--- a/docs/generated/sql/functions.md
+++ b/docs/generated/sql/functions.md
@@ -2739,7 +2739,7 @@ The swap_ordinate_string parameter is a 2-character string naming the ordinates
difference(source: string, target: string) → string | Convert two strings to their Soundex codes and then reports the number of matching code positions.
+difference(source: string, target: string) → int | Convert two strings to their Soundex codes and then reports the number of matching code positions.
| Immutable |
encode(data: bytes, format: string) → string | Encodes data using format (hex / escape / base64 ).
| Immutable |
diff --git a/pkg/sql/logictest/testdata/logic_test/fuzzystrmatch b/pkg/sql/logictest/testdata/logic_test/fuzzystrmatch
index 3454db635570..de2a2258b9ec 100644
--- a/pkg/sql/logictest/testdata/logic_test/fuzzystrmatch
+++ b/pkg/sql/logictest/testdata/logic_test/fuzzystrmatch
@@ -35,22 +35,22 @@ SELECT soundex('hello world!')
----
H464
-query TTT
+query TTI
SELECT soundex('Anne'), soundex('Ann'), difference('Anne', 'Ann');
----
A500 A500 4
-query TTT
+query TTI
SELECT soundex('Anne'), soundex('Andrew'), difference('Anne', 'Andrew');
----
A500 A536 2
-query TTT
+query TTI
SELECT soundex('Anne'), soundex('Margaret'), difference('Anne', 'Margaret');
----
A500 M626 0
-query TTTT
+query TTTI
SELECT soundex('Anne'), soundex(NULL), difference('Anne', NULL), difference(NULL, 'Bob');
----
A500 NULL NULL NULL
diff --git a/pkg/sql/sem/builtins/builtins.go b/pkg/sql/sem/builtins/builtins.go
index bd7c889ada1c..c0b172988521 100644
--- a/pkg/sql/sem/builtins/builtins.go
+++ b/pkg/sql/sem/builtins/builtins.go
@@ -28,7 +28,6 @@ import (
"math/rand"
"net"
"regexp/syntax"
- "strconv"
"strings"
"time"
"unicode"
@@ -3819,11 +3818,11 @@ value if you rely on the HLC for accuracy.`,
tree.FunctionProperties{Category: builtinconstants.CategoryString},
tree.Overload{
Types: tree.ParamTypes{{Name: "source", Typ: types.String}, {Name: "target", Typ: types.String}},
- ReturnType: tree.FixedReturnType(types.String),
+ ReturnType: tree.FixedReturnType(types.Int),
Fn: func(_ context.Context, _ *eval.Context, args tree.Datums) (tree.Datum, error) {
s, t := string(tree.MustBeDString(args[0])), string(tree.MustBeDString(args[1]))
diff := fuzzystrmatch.Difference(s, t)
- return tree.NewDString(strconv.Itoa(diff)), nil
+ return tree.NewDInt(tree.DInt(diff)), nil
},
Info: "Convert two strings to their Soundex codes and then reports the number of matching code positions.",
Volatility: volatility.Immutable,
diff --git a/pkg/sql/sem/builtins/fixed_oids.go b/pkg/sql/sem/builtins/fixed_oids.go
index 2f5b196e4528..2fc94ba12763 100644
--- a/pkg/sql/sem/builtins/fixed_oids.go
+++ b/pkg/sql/sem/builtins/fixed_oids.go
@@ -1215,7 +1215,7 @@ var builtinOidsArray = []string{
1234: `array_positions(array: anyenum[], elem: anyenum) -> int[]`,
1235: `array_positions(array: tuple[], elem: tuple) -> int[]`,
1236: `soundex(source: string) -> string`,
- 1237: `difference(source: string, target: string) -> string`,
+ 1237: `difference(source: string, target: string) -> int`,
1238: `levenshtein(source: string, target: string) -> int`,
1239: `levenshtein(source: string, target: string, ins_cost: int, del_cost: int, sub_cost: int) -> int`,
1240: `json_remove_path(val: jsonb, path: string[]) -> jsonb`,
|