Skip to content

Commit

Permalink
cherry pick pingcap#22175 to release-4.0
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
xiongjiwei authored and ti-srebot committed Jan 5, 2021
1 parent e082513 commit 551a00d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion executor/select_into.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (s *SelectIntoExec) dumpToOutfile() error {
}
s.fieldBuf = s.fieldBuf[:0]
switch col.GetType().Tp {
case mysql.TypeTiny, mysql.TypeShort, mysql.TypeInt24, mysql.TypeLong:
case mysql.TypeTiny, mysql.TypeShort, mysql.TypeInt24, mysql.TypeLong, mysql.TypeYear:
s.fieldBuf = strconv.AppendInt(s.fieldBuf, row.GetInt64(j), 10)
case mysql.TypeLonglong:
if mysql.HasUnsignedFlag(col.GetType().Flag) {
Expand Down
13 changes: 13 additions & 0 deletions executor/select_into_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,16 @@ func (s *testSuite1) TestEscapeType(c *C) {
cmpAndRm(`1,1,11,11,{"key": 11},11,11
`, outfile, c)
}

func (s *testSuite1) TestYearType(c *C) {
outfile := randomSelectFilePath("TestYearType")
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(time1 year(4) default '2030');")
tk.MustExec("insert into t values (2010), (2011), (2012);")
tk.MustExec("insert into t values ();")

tk.MustExec(fmt.Sprintf("select * from t into outfile '%v' fields terminated by ',' optionally enclosed by '\"' lines terminated by '\\n';", outfile))
cmpAndRm("2010\n2011\n2012\n2030\n", outfile, c)
}

0 comments on commit 551a00d

Please sign in to comment.