Bytes can be created by casting from a string, and are displayed using hexidecimal encoding.
<bytes>"I am some bytes";
Outputb"4920616D20736F6D65206279746573"
Available since: v3.0.0-alpha.1
Since SurrealDB 2.3.0, conversions can be performed between bytes, strings, and arrays.
-- array<int> to bytes to string <string><bytes>[ 99, 101, 108, 108, 97, 114, 32, 100, 111, 111, 114 ]; -- string to bytes to array<int> <array><bytes>"Hobbits";
Output-------- Query -------- 'cellar door' -------- Query -------- [ 72, 111, 98, 98, 105, 116, 115 ]
Available since: v3.0.0-alpha.1
A string preceded by a b
prefix can be turned into bytes as long as the string represents a hexidecimal value.
b"486F6262697473"; <string>b"486F6262697473"; <string>b"This won't work though";
Output-------- Query -------- encoding::base64::decode("SG9iYml0cw") -------- Query -------- 'Hobbits' -------- Query -------- "There was a problem with the database: Parse error: Unexpected character `T` expected hexidecimal digit --> [1:11] | 1 | <string>b\"This won't work though\"; | ^ "