Blob Functions
This section describes functions and operators for examining and manipulating BLOB values.
| Function | Description |
|---|---|
arg1 || arg2 | Concatenates two strings, lists, or blobs. Any NULL input results in NULL. See also concat(arg1, arg2, ...) and list_concat(list1, list2, ...). |
base64(blob) | Alias for to_base64. |
decode(blob[, on_error]) | Converts blob to VARCHAR. The optional on_error parameter controls handling of invalid UTF-8: 'strict' (default, throws error), 'replace' (replaces invalid characters with ?), or 'ignore' (removes invalid characters). |
encode(string) | Converts the string to BLOB. Converts UTF-8 characters into literal encoding. |
from_base64(string) | Converts a base64 encoded string to a character string (BLOB). |
from_binary(value) | Alias for unbin. |
from_hex(value) | Alias for unhex. |
hex(blob) | Converts blob to VARCHAR using hexadecimal encoding. |
md5(blob) | Returns the MD5 hash of the blob as a VARCHAR. |
md5_number(blob) | Returns the MD5 hash of the blob as a HUGEINT. |
octet_length(blob) | Number of bytes in blob. |
read_blob(source) | Returns the content from source (a filename, a list of filenames, or a glob pattern) as a BLOB. See the read_blob guide for more details. |
repeat(blob, count) | Repeats the blob count number of times. |
sha1(blob) | Returns a VARCHAR with the SHA-1 hash of the blob. |
sha256(blob) | Returns a VARCHAR with the SHA-256 hash of the blob. |
to_base64(blob) | Converts a blob to a base64 encoded string. |
to_hex(blob) | Alias for hex. |
unbin(value) | Converts a value from binary representation to a blob. |
unhex(value) | Converts a value from hexadecimal representation to a blob. |
arg1 || arg2
Concatenates two strings, lists, or blobs. Any NULL input results in NULL. See also concat(arg1, arg2, ...) and list_concat(list1, list2, ...).
SELECT 'Serene' || 'DB' AS string_concat, [1, 2, 3] || [4, 5, 6] AS list_concat, '\xAA'::BLOB || '\xBB'::BLOB AS blob_concat; string_concat | list_concat | blob_concat---------------+---------------+------------- SereneDB | {1,2,3,4,5,6} | \\xaabbdecode(blob[, on_error])
Converts blob to VARCHAR. The optional on_error parameter controls handling of invalid UTF-8: 'strict' (default, throws error), 'replace' (replaces invalid characters with ?), or 'ignore' (removes invalid characters).
SELECT decode('\xC3BC'::BLOB) AS decode, decode('\xAA'::BLOB, 'replace') AS decode_replace; decode | decode_replace--------+---------------- ü | ?encode(string)
Converts the string to BLOB. Converts UTF-8 characters into literal encoding.
SELECT encode('my_string_with_ü') AS encode; encode--------------------------------------- \\x6d795f737472696e675f776974685fc3bcfrom_base64(string)
Converts a base64 encoded string to a character string (BLOB).
SELECT from_base64('QQ==') AS from_base64; from_base64------------- \\x41hex(blob)
Converts blob to VARCHAR using hexadecimal encoding. Alias: to_hex.
SELECT hex('\xAABB'::BLOB) AS hex; hex------ AABBmd5(blob)
Returns the MD5 hash of the blob as a VARCHAR.
SELECT md5('\xAABB'::BLOB) AS md5; md5---------------------------------- 58cea1f6b2b06520613e09af90dc1c47md5_number(blob)
Returns the MD5 hash of the blob as a HUGEINT.
SELECT md5_number('\xAABB'::BLOB) AS md5_number; md5_number---------------------------------------- 94525045605907259200829535064523132504octet_length(blob)
Number of bytes in blob.
SELECT octet_length('\xAABB'::BLOB) AS octet_length; octet_length-------------- 2read_blob(source)
Returns the content from source (a filename, a list of filenames, or a glob pattern) as a BLOB. See the read_blob guide for more details.
SELECT content FROM read_blob('hello.bin'); content---------------- \x68656c6c6f0arepeat(blob, count)
Repeats the blob count number of times.
SELECT repeat('\xAABB'::BLOB, 5) AS repeat; repeat------------------------- \\xaabbaabbaabbaabbaabbsha1(blob)
Returns a VARCHAR with the SHA-1 hash of the blob.
SELECT sha1('\xAABB'::BLOB) AS sha1; sha1------------------------------------------ 65b1e351a6cbfeb41c927222bc9ef53aad3396b0sha256(blob)
Returns a VARCHAR with the SHA-256 hash of the blob.
SELECT sha256('\xAABB'::BLOB) AS sha256; sha256------------------------------------------------------------------ d798d1fac6bd4bb1c11f50312760351013379a0ab6f0a8c0af8a506b96b2525ato_base64(blob)
Converts a blob to a base64 encoded string. Alias: base64.
SELECT to_base64('A'::BLOB) AS to_base64; to_base64----------- QQ==unbin(value)
Converts a value from binary representation to a blob. Alias: from_binary.
SELECT unbin('0110') AS unbin; unbin------- \\x06unhex(value)
Converts a value from hexadecimal representation to a blob. Alias: from_hex.
SELECT unhex('2A') AS unhex; unhex------- \\x2a