I'm converting a binary data (bytea) data type to string using encode(foo::bytea, 'base64') but the output is being split in multiple lines:
-[ RECORD 1 ]-+-----------------------------------------------------------------------
req_id | 132675
b_string | d4IF4jCCBd4GCSqGSIb3DQEHAqCCBc8wggXLAgEDMQ0wCwYJBAIBMIGYBgZngQgBAQGg+
| gY0EgYowgYcCAQAwCwYJYIZIAQAwCwYJYIZIAWUDBAIHUwUdH0JybzpY2evf+v9Xg86b+
| HSGTGYBIb/QwJQIBAgQg1M6/cJ+S39XY1lm43oenxJNLrYcc3hVw7fgwJQIBDgQgIAil+
| 1JnYbdS0p4pK07kMkb/dbMcxryx6mqbLTzx+YJ6gggQbMI2gAwIBAgIESS7vwTAKBggq+
| LUxRjUXbTgfGwUKOFwemsc4KXbsLZ13MkbNfAQ==
How can get a single string instead?
UPDATE: based on the solution by @LaurenzAlbe
Just for the completeness, this is what I end up doing the gave me the result I wanted:
translate(encode(foo::bytea, 'base64'), E'\n', '')
psql doesn't split your string in multiple lines.
It's the string that contains new-line characters (ASCII 10), and psql displays them accurately. The + at the end of every line is psql's way of telling you that the value is continued in the next line.
You can use the unaligned mode (psql option -A) to get rid of the +, but the output format is less attractive then.
You can get rid of the newlines in a string with
SELECT translate(..., E'\n', '');
decode will be able to handle such a string.
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