I have string 'test\data'
or just one backslash symbol '\'
.
How it convert to bytea?
The bytea data type allows the storage of binary strings or what is typically thought of as “raw bytes”. Materialize supports both the typical formats for input and output: the hex format and the historical PostgreSQL escape format. The hex format is preferred.
The LTRIM() function removes all characters, spaces by default, from the beginning of a string. The RTRIM() function removes all characters, spaces by default, from the end of a string. The BTRIM function is the combination of the LTRIM() and RTRIM() functions.
SUBSTRING() function The PostgreSQL substring function is used to extract a string containing a specific number of characters from a particular position of a given string. The main string from where the character to be extracted. Optional. The position of the string from where the extracting will be starting.
PostgreSQL DECODE() function is used to decode or extract the binary data from the input string, which is in textual format and which has been encoded by using PostgreSQL Encode() function.
Backlashes need special handling if casted from to bytea
see src/backend/utils/adt/varlena.c
.
Thus escape each backslash using replace('test\data', '\', '\\')::bytea
before casting to bytea
.
You could also use the already suggested function convert_to(text, encoding) bytea
. But note that this function is not IMMUTABLE
and thus it can't be used in any context out of the box.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With