Skip to content

sql: repurpose the syntax x'...' for byte array literals.#13094

Merged
knz merged 1 commit intocockroachdb:masterfrom
knz:hexa-literals
Jan 24, 2017
Merged

sql: repurpose the syntax x'...' for byte array literals.#13094
knz merged 1 commit intocockroachdb:masterfrom
knz:hexa-literals

Conversation

@knz
Copy link
Copy Markdown
Contributor

@knz knz commented Jan 23, 2017

Prior to this patch this syntax would produce string literals. Like
for all string values it would also check that the string does not
contain invalid UTF-8 sequences, so it was not usable to enter byte
array constants. Meanwhile there was no convenient syntax to enter
arbitrary byte sequences using hex codes only (like hash values,
binary encoded data, etc).

As this feature was originally intended to mimic MySQL's similar
syntax, which does serve to produce byte arrays, this patch aligns the
feature more closely with its original intent by ensuring the syntax
produces byte array literals instead of string literals.

Its usage for string literals is still possible however by means of a
simple cast.

Fixes #13049.


This change is Reviewable

@jordanlewis
Copy link
Copy Markdown
Member

Like magic! LGTM. Could you add a test case illustrating the cast to string, just for completeness?

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Jan 23, 2017 via email

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Jan 23, 2017

TFYR :)

@@ -1042,7 +1042,7 @@ SELECT 0x FROM t
},
{
`SELECT x'fail' FROM t`,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also like to see an error case with the valid characters but wrong number of characters: SELECT x'01a'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Prior to this patch this syntax would produce string literals.  Like
for all string values it would also check that the string does not
contain invalid UTF-8 sequences, so it was not usable to enter byte
array constants. Meanwhile there was no convenient syntax to enter
arbitrary byte sequences using hex codes only (like hash values,
binary encoded data, etc).

As this feature was originally intended to mimic MySQL's similar
syntax, which does serve to produce byte arrays, this patch aligns the
feature more closely with its original intent by ensuring the syntax
produces byte array literals instead of string literals.

Its usage for string literals is still possible however by means of a
simple cast.
@knz knz merged commit f79e480 into cockroachdb:master Jan 24, 2017
@knz knz deleted the hexa-literals branch January 24, 2017 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sql: syntax X'...' should be byte array not string

4 participants