Contents
octet_length()
A function returning the number of bytes in the provided parameter
octet_length()
is a system function which returns the number of bytes (octets) in the provided parameter.
octet_length()
was added in PostgreSQL 6.4.
Usage
octet_length ( text ) → integer
octet_length ( bytea ) → integer
octet_length ( bit ) → integer
Change history
- PostgreSQL 6.4
- added (commit f554af0a)
Examples
Number of bytes in a simple ASCII string:
postgres=# SELECT octet_length('ABC'); octet_length -------------- 3 (1 row)
Number of bytes in an UTF8 string containing multibyte characters:
postgres=# SELECT octet_length('ほげほげ'); octet_length -------------- 12 (1 row)
Number of bytes in a bit string:
Number of bytes in a binary string:
postgres=# SELECT octet_length('\xdeadbeef'::bytea); octet_length -------------- 4 (1 row)
References
- PostgreSQL documentation: SQL String Functions and Operators
- PostgreSQL documentation: SQL Binary String Functions and Operators
- PostgreSQL documentation: Bit String Functions