Skip to content

Commit

Permalink
Merge pull request cockroachdb#20657 from justinj/uni-arrays
Browse files Browse the repository at this point in the history
sql: support printing unicode characters in arrays
  • Loading branch information
justinj authored Dec 15, 2017
2 parents 593dcfe + 7fa53a6 commit e967058
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/sql/lex/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package lex

import (
"bytes"
"unicode"
"unicode/utf8"

"github.com/cockroachdb/cockroach/pkg/util/stringencoding"
Expand Down Expand Up @@ -124,9 +125,9 @@ func EncodeSQLStringInsideArray(buf *bytes.Buffer, in string) {
// Loop through each unicode code point.
for i, r := range in {
ch := byte(r)
if r >= 0x20 && r < 0x7F && !stringencoding.NeedEscape(ch) && ch != '"' {
if unicode.IsPrint(r) && !stringencoding.NeedEscape(ch) && ch != '"' {
// Character is printable doesn't need escaping - just print it out.
buf.WriteByte(ch)
buf.WriteRune(r)
} else {
stringencoding.EncodeEscapedChar(buf, in, r, ch, i, '"')
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/array
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ SELECT NULL::INT[]
----
NULL

# #19821

query T
SELECT ARRAY['one', 'two', 'fünf']
----
{"one","two","fünf"}

query T
SELECT ARRAY[e'\n', e'g\x10h']
----
Expand Down

0 comments on commit e967058

Please sign in to comment.