PostgreSQL
9.5. Binary String Functions and Operators
This section describes functions and operators for examining and manipulating values of type bytea
.
SQL defines some string functions that use key words, rather than commas, to separate arguments. Details are in Table 9.12. PostgreSQL also provides versions of these functions that use the regular function invocation syntax (see Table 9.13).
Note
The sample results shown on this page assume that the server parameter bytea_output
is set to escape
(the traditional PostgreSQL format).
Table 9.12. SQL Binary String Functions and Operators
Function | Return Type | Description | Example | Result |
---|---|---|---|---|
`string |
`` `_`+string`_ |
|
String concatenation |
|
`+'\\Post'::bytea |
'\047gres\000'::bytea+` |
|
|
|
|
Number of bytes in binary string |
|
|
|
|
Replace substring |
|
|
|
|
Location of specified substring |
|
|
|
|
Extract substring |
|
|
|
+
Additional binary string manipulation functions are available and are listed in Table 9.13. Some of them are used internally to implement the SQL-standard string functions listed in Table 9.12.
Table 9.13. Other Binary String Functions
Function | Return Type | Description | Example | Result |
---|---|---|---|---|
|
|
Remove the longest string containing only bytes appearing in `bytes |
|
|
|
|
Decode binary data from textual representation in `string |
|
|
|
|
Encode binary data into a textual representation. Supported formats are: |
|
|
|
|
Extract bit from string |
|
|
|
|
Extract byte from string |
|
|
|
|
Length of binary string |
|
|
|
|
Calculates the MD5 hash of `string`, returning the result in hexadecimal |
|
|
|
|
Set bit in string |
|
|
|
|
Set byte in string |
|
|
|
|
SHA-224 hash |
|
|
|
|
SHA-256 hash |
|
|
|
|
SHA-384 hash |
|
|
|
|
SHA-512 hash |
|
|
+
get_byte
and set_byte
number the first byte of a binary string as byte 0. get_bit
and set_bit
number bits from the right within each byte; for example bit 0 is the least significant bit of the first byte, and bit 15 is the most significant bit of the second byte.
Note that for historic reasons, the function md5
returns a hex-encoded value of type text
whereas the SHA-2 functions return type bytea
. Use the functions encode
and decode
to convert between the two, for example encode(sha256('abc'), 'hex')
to get a hex-encoded text representation.
See also the aggregate function string_agg
in Section 9.20 and the large object functions in Section 34.4.
Prev | Up | Next |
---|---|---|
9.4. String Functions and Operators |
9.6. Bit String Functions and Operators |
Submit correction
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.
Copyright © 1996-2023 The PostgreSQL Global Development Group