diff --git a/go/mysql/datetime/types.go b/go/mysql/datetime/types.go index a57ab51eaeb..8d7c2524722 100644 --- a/go/mysql/datetime/types.go +++ b/go/mysql/datetime/types.go @@ -314,12 +314,16 @@ func (d Date) Week(mode int) int { year, week := d.SundayWeek() if year < d.Year() { return 0 + } else if year > d.Year() { + return 53 } return week case 1: year, week := d.ISOWeek() if year < d.Year() { return 0 + } else if year > d.Year() { + return 53 } return week case 2: @@ -332,12 +336,16 @@ func (d Date) Week(mode int) int { year, week := d.Sunday4DayWeek() if year < d.Year() { return 0 + } else if year > d.Year() { + return 53 } return week case 5: year, week := d.MondayWeek() if year < d.Year() { return 0 + } else if year > d.Year() { + return 53 } return week case 6: diff --git a/go/vt/vtgate/evalengine/compiler_test.go b/go/vt/vtgate/evalengine/compiler_test.go index 4c21de2dde6..b38b5f14557 100644 --- a/go/vt/vtgate/evalengine/compiler_test.go +++ b/go/vt/vtgate/evalengine/compiler_test.go @@ -476,6 +476,22 @@ func TestCompilerSingle(t *testing.T) { expression: `case when null is null then 23 else null end`, result: `INT64(23)`, }, + { + expression: `week('2023-12-31', 4)`, + result: `INT64(53)`, + }, + { + expression: `week('2023-12-31', 2)`, + result: `INT64(53)`, + }, + { + expression: `week('2024-12-31', 1)`, + result: `INT64(53)`, + }, + { + expression: `week('2024-12-31', 5)`, + result: `INT64(53)`, + }, } for _, tc := range testCases {