diff --git a/go/vt/vtctl/grpcvtctldserver/query.go b/go/vt/vtctl/grpcvtctldserver/query.go index 100e71b92c5..2aba4d3f15f 100644 --- a/go/vt/vtctl/grpcvtctldserver/query.go +++ b/go/vt/vtctl/grpcvtctldserver/query.go @@ -190,6 +190,13 @@ func valueToVTTime(s string) (*vttime.Time, error) { return nil, nil } + // Handle MySQL's zero/NULL timestamp (0000-00-00 00:00:00) + // This is what MySQL returns for NULL datetime values when the connection + // is not configured to return SQL NULL values. + if len(s) >= 10 && s[:10] == "0000-00-00" { + return nil, nil + } + gotime, err := time.ParseInLocation(sqltypes.TimestampFormat, s, time.Local) if err != nil { return nil, err diff --git a/go/vt/vtctl/grpcvtctldserver/query_test.go b/go/vt/vtctl/grpcvtctldserver/query_test.go index 6073d3bc395..65bfb1fb31c 100644 --- a/go/vt/vtctl/grpcvtctldserver/query_test.go +++ b/go/vt/vtctl/grpcvtctldserver/query_test.go @@ -122,6 +122,16 @@ func TestValueToVTTime(t *testing.T) { value: "", expected: nil, }, + { + name: "MySQL zero timestamp", + value: "0000-00-00 00:00:00", + expected: nil, + }, + { + name: "MySQL zero timestamp with microseconds", + value: "0000-00-00 00:00:00.000000", + expected: nil, + }, { name: "parse error", value: "2006/01/02",