{"Entry":{"collection":"type","key":"bytea","name":"bytea","aliases":[],"metadata":{"aliases":[],"category":"Other built-in types","content_hash":"759ed08fafb74eeb326b6975e8be2639ef973f4edf67f5656fe98e91bc149d0c","imported_at":"2026-09-30T00:40:35.517993+08:00","name":"bytea","name_zh":"","slug":"bytea","summary":"binary data ( “ byte array ” )"}},"Definition":{"Collection":"type","Key":"bytea","SourceDatabase":"center","Version":"18","SourceTable":"data_type","SourceKey":"bytea","SourceRevision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","Facts":{"aliases":[],"casts":[{"castcontext":"e","castfunc":"bytea(int2)","castmethod":"f","castsource":"int2","casttarget":"bytea"},{"castcontext":"e","castfunc":"bytea(int4)","castmethod":"f","castsource":"int4","casttarget":"bytea"},{"castcontext":"e","castfunc":"bytea(int8)","castmethod":"f","castsource":"int8","casttarget":"bytea"},{"castcontext":"e","castfunc":"int2(bytea)","castmethod":"f","castsource":"bytea","casttarget":"int2"},{"castcontext":"e","castfunc":"int4(bytea)","castmethod":"f","castsource":"bytea","casttarget":"int4"},{"castcontext":"e","castfunc":"int8(bytea)","castmethod":"f","castsource":"bytea","casttarget":"int8"},{"castcontext":"i","castfunc":"0","castmethod":"b","castsource":"pg_ndistinct","casttarget":"bytea"},{"castcontext":"i","castfunc":"0","castmethod":"b","castsource":"pg_dependencies","casttarget":"bytea"},{"castcontext":"i","castfunc":"0","castmethod":"b","castsource":"pg_mcv_list","casttarget":"bytea"}],"catalog":{"array_type_name":"_bytea","array_type_oid":"1001","descr":"variable-length string, binary values escaped","oid":"17","typacl":"_null_","typalign":"i","typanalyze":"-","typarray":"0","typbasetype":"0","typbyval":"f","typcategory":"U","typcollation":"0","typdefault":"_null_","typdefaultbin":"_null_","typdelim":"','","typelem":"0","typinput":"byteain","typisdefined":"t","typispreferred":"f","typlen":"-1","typmodin":"-","typmodout":"-","typname":"bytea","typnamespace":"pg_catalog","typndims":"0","typnotnull":"f","typoutput":"byteaout","typowner":"POSTGRES","typreceive":"bytearecv","typrelid":"0","typsend":"byteasend","typstorage":"x","typsubscript":"-","typtype":"b","typtypmod":"-1"},"comparison_data":{"aliases":[],"casts":[{"castcontext":"e","castfunc":"bytea(int2)","castmethod":"f","castsource":"int2","casttarget":"bytea"},{"castcontext":"e","castfunc":"bytea(int4)","castmethod":"f","castsource":"int4","casttarget":"bytea"},{"castcontext":"e","castfunc":"bytea(int8)","castmethod":"f","castsource":"int8","casttarget":"bytea"},{"castcontext":"e","castfunc":"int2(bytea)","castmethod":"f","castsource":"bytea","casttarget":"int2"},{"castcontext":"e","castfunc":"int4(bytea)","castmethod":"f","castsource":"bytea","casttarget":"int4"},{"castcontext":"e","castfunc":"int8(bytea)","castmethod":"f","castsource":"bytea","casttarget":"int8"},{"castcontext":"i","castfunc":"0","castmethod":"b","castsource":"pg_dependencies","casttarget":"bytea"},{"castcontext":"i","castfunc":"0","castmethod":"b","castsource":"pg_mcv_list","casttarget":"bytea"},{"castcontext":"i","castfunc":"0","castmethod":"b","castsource":"pg_ndistinct","casttarget":"bytea"}],"catalog":{"array_type_name":"_bytea","typacl":"_null_","typalign":"i","typanalyze":"-","typarray":"_bytea","typbasetype":"0","typbyval":"f","typcategory":"U","typcollation":"0","typdefault":"_null_","typdefaultbin":"_null_","typdelim":",","typelem":"0","typinput":"byteain","typisdefined":"t","typispreferred":"f","typlen":"-1","typmodin":"-","typmodout":"-","typname":"bytea","typndims":"0","typnotnull":"f","typoutput":"byteaout","typreceive":"bytearecv","typrelid":"0","typsend":"byteasend","typstorage":"x","typsubscript":"-","typtype":"b","typtypmod":"-1"},"facts":[{"label":"Catalog name","value":"pg_catalog.bytea"},{"label":"Declared length","value":"Variable length (varlena)"},{"label":"Documented declaration","value":"bytea"},{"label":"Input function","value":"byteain"},{"label":"Output function","value":"byteaout"},{"label":"Storage Size","value":"1 or 4 bytes plus the actual binary string"},{"label":"Storage strategy","value":"extended"},{"label":"Type OID","value":"17"},{"label":"Type kind","value":"Base type"}],"operator_classes":[{"opcdefault":"f","opcfamily":"brin/bytea_bloom_ops","opcintype":"bytea","opckeytype":"bytea","opcmethod":"brin","opcname":"bytea_bloom_ops"},{"opcdefault":"t","opcfamily":"brin/bytea_minmax_ops","opcintype":"bytea","opckeytype":"bytea","opcmethod":"brin","opcname":"bytea_minmax_ops"},{"opcdefault":"t","opcfamily":"btree/bytea_ops","opcintype":"bytea","opckeytype":"0","opcmethod":"btree","opcname":"bytea_ops"},{"opcdefault":"t","opcfamily":"hash/bytea_ops","opcintype":"bytea","opckeytype":"0","opcmethod":"hash","opcname":"bytea_ops"}],"operators":[{"oprcanhash":"f","oprcanmerge":"f","oprcode":"byteacat","oprcom":"0","oprjoin":"-","oprkind":"b","oprleft":"bytea","oprname":"||","oprnegate":"0","oprrest":"-","oprresult":"bytea","oprright":"bytea"},{"oprcanhash":"f","oprcanmerge":"f","oprcode":"byteage","oprcom":"\u003c=(bytea,bytea)","oprjoin":"scalargejoinsel","oprkind":"b","oprleft":"bytea","oprname":"\u003e=","oprnegate":"\u003c(bytea,bytea)","oprrest":"scalargesel","oprresult":"bool","oprright":"bytea"},{"oprcanhash":"f","oprcanmerge":"f","oprcode":"byteagt","oprcom":"\u003c(bytea,bytea)","oprjoin":"scalargtjoinsel","oprkind":"b","oprleft":"bytea","oprname":"\u003e","oprnegate":"\u003c=(bytea,bytea)","oprrest":"scalargtsel","oprresult":"bool","oprright":"bytea"},{"oprcanhash":"f","oprcanmerge":"f","oprcode":"byteale","oprcom":"\u003e=(bytea,bytea)","oprjoin":"scalarlejoinsel","oprkind":"b","oprleft":"bytea","oprname":"\u003c=","oprnegate":"\u003e(bytea,bytea)","oprrest":"scalarlesel","oprresult":"bool","oprright":"bytea"},{"oprcanhash":"f","oprcanmerge":"f","oprcode":"bytealike","oprcom":"0","oprjoin":"likejoinsel","oprkind":"b","oprleft":"bytea","oprname":"~~","oprnegate":"!~~(bytea,bytea)","oprrest":"likesel","oprresult":"bool","oprright":"bytea"},{"oprcanhash":"f","oprcanmerge":"f","oprcode":"bytealt","oprcom":"\u003e(bytea,bytea)","oprjoin":"scalarltjoinsel","oprkind":"b","oprleft":"bytea","oprname":"\u003c","oprnegate":"\u003e=(bytea,bytea)","oprrest":"scalarltsel","oprresult":"bool","oprright":"bytea"},{"oprcanhash":"f","oprcanmerge":"f","oprcode":"byteane","oprcom":"\u003c\u003e(bytea,bytea)","oprjoin":"neqjoinsel","oprkind":"b","oprleft":"bytea","oprname":"\u003c\u003e","oprnegate":"=(bytea,bytea)","oprrest":"neqsel","oprresult":"bool","oprright":"bytea"},{"oprcanhash":"f","oprcanmerge":"f","oprcode":"byteanlike","oprcom":"0","oprjoin":"nlikejoinsel","oprkind":"b","oprleft":"bytea","oprname":"!~~","oprnegate":"~~(bytea,bytea)","oprrest":"nlikesel","oprresult":"bool","oprright":"bytea"},{"oprcanhash":"t","oprcanmerge":"t","oprcode":"byteaeq","oprcom":"=(bytea,bytea)","oprjoin":"eqjoinsel","oprkind":"b","oprleft":"bytea","oprname":"=","oprnegate":"\u003c\u003e(bytea,bytea)","oprrest":"eqsel","oprresult":"bool","oprright":"bytea"}],"ranges":[]},"comparison_hash":"57a42e92d9e379de8dd1fabd68c620882852d79d2ab96850b2e678543bfdced1","coverage":"source inventory; exact declared input types for operator classes","description":["binary data ( “ byte array ” )"],"facts":[{"label":"Catalog name","value":"pg_catalog.bytea"},{"label":"Type OID","value":"17"},{"label":"Type kind","value":"Base type"},{"label":"Declared length","value":"Variable length (varlena)"},{"label":"Storage strategy","value":"extended"},{"label":"Input function","value":"byteain"},{"label":"Output function","value":"byteaout"},{"label":"Documented declaration","value":"bytea"},{"label":"Storage Size","value":"1 or 4 bytes plus the actual binary string"},{"label":"Manual description","value":"variable-length binary string"}],"manual_documentation":"dedicated family chapter","manual_html":"\u003cdiv class=\"sect1\" id=\"DATATYPE-BINARY\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch2 class=\"title\"\u003e8.4. Binary Data Types \u003c/h2\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\u003cp\u003eThe \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e data type allows storage of binary strings; see \u003ca class=\"xref\" href=\"/docs/18/datatype-binary.html#DATATYPE-BINARY-TABLE\" title=\"Table 8.6. Binary Data Types\"\u003eTable 8.6\u003c/a\u003e.\u003c/p\u003e\n\u003cdiv class=\"table\" id=\"DATATYPE-BINARY-TABLE\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eTable 8.6. Binary Data Types\u003c/strong\u003e\u003c/p\u003e\n\u003cdiv class=\"table-contents\"\u003e\n\u003ctable class=\"table\"\u003e\n\n\n\n\n\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eName\u003c/th\u003e\n\u003cth\u003eStorage Size\u003c/th\u003e\n\u003cth\u003eDescription\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003ebytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e1 or 4 bytes plus the actual binary string\u003c/td\u003e\n\u003ctd\u003evariable-length binary string\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003cbr class=\"table-break\"\u003e\n\u003cp\u003eA binary string is a sequence of octets (or bytes). Binary strings are distinguished from character strings in two ways. First, binary strings specifically allow storing octets of value zero and other \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003enon-printable\u003c/span\u003e”\u003c/span\u003e octets (usually, octets outside the decimal range 32 to 126). Character strings disallow zero octets, and also disallow any other octet values and sequences of octet values that are invalid according to the database's selected character set encoding. Second, operations on binary strings process the actual bytes, whereas the processing of character strings depends on locale settings. In short, binary strings are appropriate for storing data that the programmer thinks of as \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003eraw bytes\u003c/span\u003e”\u003c/span\u003e, whereas character strings are appropriate for storing text.\u003c/p\u003e\n\u003cp\u003eThe \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e type supports two formats for input and output: \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003ehex\u003c/span\u003e”\u003c/span\u003e format and \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e's historical \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003eescape\u003c/span\u003e”\u003c/span\u003e format. Both of these are always accepted on input. The output format depends on the configuration parameter \u003ca class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-BYTEA-OUTPUT\"\u003ebytea_output\u003c/a\u003e; the default is hex. (Note that the hex format was introduced in \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 9.0; earlier versions and some tools don't understand it.)\u003c/p\u003e\n\u003cp\u003eThe SQL standard defines a different binary string type, called \u003ccode class=\"type\"\u003eBLOB\u003c/code\u003e or \u003ccode class=\"type\"\u003eBINARY LARGE OBJECT\u003c/code\u003e. The input format is different from \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e, but the provided functions and operators are mostly the same.\u003c/p\u003e\n\u003cdiv class=\"sect2\" id=\"DATATYPE-BINARY-BYTEA-HEX-FORMAT\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003e8.4.1. \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e Hex Format \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThe \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003ehex\u003c/span\u003e”\u003c/span\u003e format encodes binary data as 2 hexadecimal digits per byte, most significant nibble first. The entire string is preceded by the sequence \u003ccode class=\"literal\"\u003e\\x\u003c/code\u003e (to distinguish it from the escape format). In some contexts, the initial backslash may need to be escaped by doubling it (see \u003ca class=\"xref\" href=\"/docs/18/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS\" title=\"4.1.2.1. String Constants\"\u003eSection 4.1.2.1\u003c/a\u003e). For input, the hexadecimal digits can be either upper or lower case, and whitespace is permitted between digit pairs (but not within a digit pair nor in the starting \u003ccode class=\"literal\"\u003e\\x\u003c/code\u003e sequence). The hex format is compatible with a wide range of external applications and protocols, and it tends to be faster to convert than the escape format, so its use is preferred.\u003c/p\u003e\n\u003cp\u003eExample:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003eSET bytea_output = 'hex';\n\nSELECT '\\xDEADBEEF'::bytea;\n   bytea\n------------\n \\xdeadbeef\n\u003c/pre\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"DATATYPE-BINARY-BYTEA-ESCAPE-FORMAT\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003e8.4.2. \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e Escape Format \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThe \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003eescape\u003c/span\u003e”\u003c/span\u003e format is the traditional \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e format for the \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e type. It takes the approach of representing a binary string as a sequence of ASCII characters, while converting those bytes that cannot be represented as an ASCII character into special escape sequences. If, from the point of view of the application, representing bytes as characters makes sense, then this representation can be convenient. But in practice it is usually confusing because it fuzzes up the distinction between binary strings and character strings, and also the particular escape mechanism that was chosen is somewhat unwieldy. Therefore, this format should probably be avoided for most new applications.\u003c/p\u003e\n\u003cp\u003eWhen entering \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e values in escape format, octets of certain values \u003cspan class=\"emphasis\"\u003e\u003cem\u003emust\u003c/em\u003e\u003c/span\u003e be escaped, while all octet values \u003cspan class=\"emphasis\"\u003e\u003cem\u003ecan\u003c/em\u003e\u003c/span\u003e be escaped. In general, to escape an octet, convert it into its three-digit octal value and precede it by a backslash. Backslash itself (octet decimal value 92) can alternatively be represented by double backslashes. \u003ca class=\"xref\" href=\"/docs/18/datatype-binary.html#DATATYPE-BINARY-SQLESC\" title=\"Table 8.7. bytea Literal Escaped Octets\"\u003eTable 8.7\u003c/a\u003e shows the characters that must be escaped, and gives the alternative escape sequences where applicable.\u003c/p\u003e\n\u003cdiv class=\"table\" id=\"DATATYPE-BINARY-SQLESC\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eTable 8.7. \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e Literal Escaped Octets\u003c/strong\u003e\u003c/p\u003e\n\u003cdiv class=\"table-contents\"\u003e\n\u003ctable class=\"table\"\u003e\n\n\n\n\n\n\n\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eDecimal Octet Value\u003c/th\u003e\n\u003cth\u003eDescription\u003c/th\u003e\n\u003cth\u003eEscaped Input Representation\u003c/th\u003e\n\u003cth\u003eExample\u003c/th\u003e\n\u003cth\u003eHex Representation\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003e0\u003c/td\u003e\n\u003ctd\u003ezero octet\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e'\\000'\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e'\\000'::bytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e\\x00\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e39\u003c/td\u003e\n\u003ctd\u003esingle quote\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e''''\u003c/code\u003e or \u003ccode class=\"literal\"\u003e'\\047'\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e''''::bytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e\\x27\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e92\u003c/td\u003e\n\u003ctd\u003ebackslash\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e'\\\\'\u003c/code\u003e or \u003ccode class=\"literal\"\u003e'\\134'\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e'\\\\'::bytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e\\x5c\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e0 to 31 and 127 to 255\u003c/td\u003e\n\u003ctd\u003e\u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003enon-printable\u003c/span\u003e”\u003c/span\u003e octets\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e'\\\u003cem class=\"replaceable\"\u003e\u003ccode\u003exxx'\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e (octal value)\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e'\\001'::bytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e\\x01\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003cbr class=\"table-break\"\u003e\n\u003cp\u003eThe requirement to escape \u003cspan class=\"emphasis\"\u003e\u003cem\u003enon-printable\u003c/em\u003e\u003c/span\u003e octets varies depending on locale settings. In some instances you can get away with leaving them unescaped.\u003c/p\u003e\n\u003cp\u003eThe reason that single quotes must be doubled, as shown in \u003ca class=\"xref\" href=\"/docs/18/datatype-binary.html#DATATYPE-BINARY-SQLESC\" title=\"Table 8.7. bytea Literal Escaped Octets\"\u003eTable 8.7\u003c/a\u003e, is that this is true for any string literal in an SQL command. The generic string-literal parser consumes the outermost single quotes and reduces any pair of single quotes to one data character. What the \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e input function sees is just one single quote, which it treats as a plain data character. However, the \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e input function treats backslashes as special, and the other behaviors shown in \u003ca class=\"xref\" href=\"/docs/18/datatype-binary.html#DATATYPE-BINARY-SQLESC\" title=\"Table 8.7. bytea Literal Escaped Octets\"\u003eTable 8.7\u003c/a\u003e are implemented by that function.\u003c/p\u003e\n\u003cp\u003eIn some contexts, backslashes must be doubled compared to what is shown above, because the generic string-literal parser will also reduce pairs of backslashes to one data character; see \u003ca class=\"xref\" href=\"/docs/18/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS\" title=\"4.1.2.1. String Constants\"\u003eSection 4.1.2.1\u003c/a\u003e.\u003c/p\u003e\n\u003cp\u003e\u003ccode class=\"type\"\u003eBytea\u003c/code\u003e octets are output in \u003ccode class=\"literal\"\u003ehex\u003c/code\u003e format by default. If you change \u003ca class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-BYTEA-OUTPUT\"\u003ebytea_output\u003c/a\u003e to \u003ccode class=\"literal\"\u003eescape\u003c/code\u003e, \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003enon-printable\u003c/span\u003e”\u003c/span\u003e octets are converted to their equivalent three-digit octal value and preceded by one backslash. Most \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003eprintable\u003c/span\u003e”\u003c/span\u003e octets are output by their standard representation in the client character set, e.g.:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003eSET bytea_output = 'escape';\n\nSELECT 'abc \\153\\154\\155 \\052\\251\\124'::bytea;\n     bytea\n----------------\n abc klm *\\251T\n\u003c/pre\u003e\n\u003cp\u003eThe octet with decimal value 92 (backslash) is doubled in the output. Details are in \u003ca class=\"xref\" href=\"/docs/18/datatype-binary.html#DATATYPE-BINARY-RESESC\" title=\"Table 8.8. bytea Output Escaped Octets\"\u003eTable 8.8\u003c/a\u003e.\u003c/p\u003e\n\u003cdiv class=\"table\" id=\"DATATYPE-BINARY-RESESC\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eTable 8.8. \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e Output Escaped Octets\u003c/strong\u003e\u003c/p\u003e\n\u003cdiv class=\"table-contents\"\u003e\n\u003ctable class=\"table\"\u003e\n\n\n\n\n\n\n\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eDecimal Octet Value\u003c/th\u003e\n\u003cth\u003eDescription\u003c/th\u003e\n\u003cth\u003eEscaped Output Representation\u003c/th\u003e\n\u003cth\u003eExample\u003c/th\u003e\n\u003cth\u003eOutput Result\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003e92\u003c/td\u003e\n\u003ctd\u003ebackslash\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e\\\\\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e'\\134'::bytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e\\\\\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e0 to 31 and 127 to 255\u003c/td\u003e\n\u003ctd\u003e\u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003enon-printable\u003c/span\u003e”\u003c/span\u003e octets\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e\\\u003cem class=\"replaceable\"\u003e\u003ccode\u003exxx\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e (octal value)\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e'\\001'::bytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e\\001\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e32 to 126\u003c/td\u003e\n\u003ctd\u003e\u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003eprintable\u003c/span\u003e”\u003c/span\u003e octets\u003c/td\u003e\n\u003ctd\u003eclient character set representation\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e'\\176'::bytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e~\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003cbr class=\"table-break\"\u003e\n\u003cp\u003eDepending on the front end to \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e you use, you might have additional work to do in terms of escaping and unescaping \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e strings. For example, you might also have to escape line feeds and carriage returns if your interface automatically translates these.\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e","manual_path":"datatype-binary.html","operator_classes":[{"opcdefault":"t","opcfamily":"btree/bytea_ops","opcintype":"bytea","opckeytype":"0","opcmethod":"btree","opcname":"bytea_ops","opcnamespace":"pg_catalog","opcowner":"POSTGRES"},{"opcdefault":"t","opcfamily":"hash/bytea_ops","opcintype":"bytea","opckeytype":"0","opcmethod":"hash","opcname":"bytea_ops","opcnamespace":"pg_catalog","opcowner":"POSTGRES"},{"opcdefault":"t","opcfamily":"brin/bytea_minmax_ops","opcintype":"bytea","opckeytype":"bytea","opcmethod":"brin","opcname":"bytea_minmax_ops","opcnamespace":"pg_catalog","opcowner":"POSTGRES"},{"opcdefault":"f","opcfamily":"brin/bytea_bloom_ops","opcintype":"bytea","opckeytype":"bytea","opcmethod":"brin","opcname":"bytea_bloom_ops","opcnamespace":"pg_catalog","opcowner":"POSTGRES"}],"operators":[{"descr":"equal","oid":"1955","oid_symbol":"ByteaEqualOperator","oprcanhash":"t","oprcanmerge":"t","oprcode":"byteaeq","oprcom":"=(bytea,bytea)","oprjoin":"eqjoinsel","oprkind":"b","oprleft":"bytea","oprname":"=","oprnamespace":"pg_catalog","oprnegate":"\u003c\u003e(bytea,bytea)","oprowner":"POSTGRES","oprrest":"eqsel","oprresult":"bool","oprright":"bytea"},{"descr":"not equal","oid":"1956","oprcanhash":"f","oprcanmerge":"f","oprcode":"byteane","oprcom":"\u003c\u003e(bytea,bytea)","oprjoin":"neqjoinsel","oprkind":"b","oprleft":"bytea","oprname":"\u003c\u003e","oprnamespace":"pg_catalog","oprnegate":"=(bytea,bytea)","oprowner":"POSTGRES","oprrest":"neqsel","oprresult":"bool","oprright":"bytea"},{"descr":"less than","oid":"1957","oid_symbol":"ByteaLessOperator","oprcanhash":"f","oprcanmerge":"f","oprcode":"bytealt","oprcom":"\u003e(bytea,bytea)","oprjoin":"scalarltjoinsel","oprkind":"b","oprleft":"bytea","oprname":"\u003c","oprnamespace":"pg_catalog","oprnegate":"\u003e=(bytea,bytea)","oprowner":"POSTGRES","oprrest":"scalarltsel","oprresult":"bool","oprright":"bytea"},{"descr":"less than or equal","oid":"1958","oprcanhash":"f","oprcanmerge":"f","oprcode":"byteale","oprcom":"\u003e=(bytea,bytea)","oprjoin":"scalarlejoinsel","oprkind":"b","oprleft":"bytea","oprname":"\u003c=","oprnamespace":"pg_catalog","oprnegate":"\u003e(bytea,bytea)","oprowner":"POSTGRES","oprrest":"scalarlesel","oprresult":"bool","oprright":"bytea"},{"descr":"greater than","oid":"1959","oprcanhash":"f","oprcanmerge":"f","oprcode":"byteagt","oprcom":"\u003c(bytea,bytea)","oprjoin":"scalargtjoinsel","oprkind":"b","oprleft":"bytea","oprname":"\u003e","oprnamespace":"pg_catalog","oprnegate":"\u003c=(bytea,bytea)","oprowner":"POSTGRES","oprrest":"scalargtsel","oprresult":"bool","oprright":"bytea"},{"descr":"greater than or equal","oid":"1960","oid_symbol":"ByteaGreaterEqualOperator","oprcanhash":"f","oprcanmerge":"f","oprcode":"byteage","oprcom":"\u003c=(bytea,bytea)","oprjoin":"scalargejoinsel","oprkind":"b","oprleft":"bytea","oprname":"\u003e=","oprnamespace":"pg_catalog","oprnegate":"\u003c(bytea,bytea)","oprowner":"POSTGRES","oprrest":"scalargesel","oprresult":"bool","oprright":"bytea"},{"descr":"matches LIKE expression","oid":"2016","oid_symbol":"OID_BYTEA_LIKE_OP","oprcanhash":"f","oprcanmerge":"f","oprcode":"bytealike","oprcom":"0","oprjoin":"likejoinsel","oprkind":"b","oprleft":"bytea","oprname":"~~","oprnamespace":"pg_catalog","oprnegate":"!~~(bytea,bytea)","oprowner":"POSTGRES","oprrest":"likesel","oprresult":"bool","oprright":"bytea"},{"descr":"does not match LIKE expression","oid":"2017","oprcanhash":"f","oprcanmerge":"f","oprcode":"byteanlike","oprcom":"0","oprjoin":"nlikejoinsel","oprkind":"b","oprleft":"bytea","oprname":"!~~","oprnamespace":"pg_catalog","oprnegate":"~~(bytea,bytea)","oprowner":"POSTGRES","oprrest":"nlikesel","oprresult":"bool","oprright":"bytea"},{"descr":"concatenate","oid":"2018","oprcanhash":"f","oprcanmerge":"f","oprcode":"byteacat","oprcom":"0","oprjoin":"-","oprkind":"b","oprleft":"bytea","oprname":"||","oprnamespace":"pg_catalog","oprnegate":"0","oprowner":"POSTGRES","oprrest":"-","oprresult":"bytea","oprright":"bytea"}],"ranges":[],"related":[{"label":"pg_type catalog","url":"/wiki/catalog/pg_type/?v=18"},{"label":"pg_cast catalog","url":"/wiki/catalog/pg_cast/?v=18"},{"label":"pg_operator catalog","url":"/wiki/catalog/pg_operator/?v=18"},{"label":"pg_opclass catalog","url":"/wiki/catalog/pg_opclass/?v=18"},{"label":"Arrays","url":"/wiki/type/arrays/?v=18"},{"label":"brin index access method","url":"/wiki/indexam/brin/?v=18"},{"label":"btree index access method","url":"/wiki/indexam/btree/?v=18"},{"label":"hash index access method","url":"/wiki/indexam/hash/?v=18"}],"release":{"channel":"stable","label":"18.6","major":"18","manual_sha256":{"arrays.html":"0e1d5c5a7b4a949d4439995f44f74ad4264e050d16eb9ad2a850fbaee04032df","catalog-pg-type.html":"ea9c9313bab8e92a7da18ebc50c7ff1f908dd80999a7e0ca3bbc82ba626c58d4","datatype-binary.html":"0c03ec47b76e37888a3da7f5dcfd340128a5d356642a85185cc9ebe17856a904","datatype-bit.html":"c49124aad561636c18080b9e09572fde7785a6b9eae86f5a33283f0fd6774c37","datatype-boolean.html":"b633f663e6c8276e7056287640c413aa79dbc15d5353cee0d41653d58d376956","datatype-character.html":"c73eebe413ea709a7792e4cfc3cfe9fb68cb496ebe83c3ebaa9d09f8c40d0f73","datatype-datetime.html":"e366275d8b13845bfa4ef0d68faa093e5f3ecb708a1ec870cbcbf7e425b85699","datatype-enum.html":"cab38e53222e30cc94b24de4b33634fd22d7c93f58ebcf35f646c9b8da78fae8","datatype-geometric.html":"0eb3053cfe7d6b0a4b5592c5d7af8d97cae527e87f063c5793413bcba5c14cd9","datatype-json.html":"650162a05b660146b500a205d523374d00aee117a6a6240d30262be51b6e33e5","datatype-money.html":"8b29c14b90679683ac5c472b59a0a7e2853f32cc7db43fab417b2697a6879964","datatype-net-types.html":"96846e641cc37727ddcd8b8a1aa0dbe33cd9787760a2b4efb0dcb9403d5be63f","datatype-numeric.html":"b74619f7ac2f1ca9f85c48073df78c33dd30e464e61baba6008634534edcb500","datatype-oid.html":"8b3360302225f08ae72716ce1804596de95b568e5d31f788cb4597427b28cc38","datatype-pg-lsn.html":"339172f5107cc7eb7139bec911277647219e92a532cebd0f3da0a5dacf8195af","datatype-pseudo.html":"c7cf0b8214304bd8702c95f2142671ae5f0d631f83717f9c07d9e1f2579961b4","datatype-textsearch.html":"4b15e05be8b49a71b28aea22f2c46d0dbf639a91e7b4fe129a4c737c6daad47c","datatype-uuid.html":"292b307b3223c6182bdba687e7f69e6dca9038430143ad79d56327f6ed4c3246","datatype-xml.html":"061fc2295b7b69be704f0a741b8decd10ad721059f871fb0243c669bb54d7822","datatype.html":"e581f67c74e42006289638c8659e9b338adbfd7f068bd8bf2b3be3880fcd2254","domains.html":"82d486973ccc35d14276627a67ac76b434452f23f9ed4d8aa3fbb01fdf285fc2","functions-info.html":"78ac80bf81da2e4f4a33f3b850faa86f0f58ec54a083d6c31da557907de0df87","rangetypes.html":"e4960abc7ce8e51d794f94f1e57b099d30b7f75dd7f2b23a960eef91f6291c33","rowtypes.html":"74f99e029c3a9edfd3e18810ba3c8cb66d3aada91eb67b86476560871e6617e9","sql-createdomain.html":"e94f927196de1b0ea1ce35cd4603c1f6f544439adcc0edf1c4222358e832245b"},"ref":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_files":{"doc/src/sgml/datatype.sgml":"86328daa77e20d81d222376ec0306d9841a17104e436c08d138eb763aefb3700","src/include/catalog/pg_am.dat":"b3cb86b102a42fb0024cbd99779c9897afb40d12a71f5cc5a0e5aee7ff2f9969","src/include/catalog/pg_am.h":"3426799df799f32163fcc0765f43dbdb5e88e626acf31284fef9fc6014b69d8e","src/include/catalog/pg_cast.dat":"97911281ca2c81917394ccb2ec13367e37c6801fd461d5e1a3d2f28b911b46b2","src/include/catalog/pg_cast.h":"de585c7df687d698e7d1d100dce8a794ac9da52414ea48169191019178c8f053","src/include/catalog/pg_opclass.dat":"4ee7d3619a6aa106e1c0db55de903931c7d11b1c60ba053a022519c55f8ee668","src/include/catalog/pg_opclass.h":"9c218537806c8ef0398302faaca7f91315dfc1198c48706cebffb479b68defaf","src/include/catalog/pg_operator.dat":"5d35b9b2ef5f9797cc815263927ef8a12367fedace53e828b4e8b320e2a7f703","src/include/catalog/pg_operator.h":"621b18cfffe102413d79b746ce7a10f77fc60fdd097bac34c22b31070d3ee3c4","src/include/catalog/pg_opfamily.dat":"3b694879027b858f2ecf1fa1152b7e30c6e15a216ba99c2384291c30e9d52311","src/include/catalog/pg_opfamily.h":"e1f5fc8aebd3042df847455bf66bf755f768c2aa8a9b03d22f7ec8563eba59c0","src/include/catalog/pg_proc.dat":"1f934ce80d460159dda137714374a35f9896315ea2476709cbb4da13b38ef95a","src/include/catalog/pg_proc.h":"f7d59f07c5b95e2f3c7141762a0f576e8a3af7581ba54c27537f4d500472bea5","src/include/catalog/pg_range.dat":"5c2271f8e89e9378d1887204e5785060b77405b5f0ff3e6c719250c9c1dcfcc4","src/include/catalog/pg_range.h":"45546d952b5181f989bd9234721897fc2b37005c8e49ce2ddc156f26974c3ca4","src/include/catalog/pg_type.dat":"5f5887b75677cba2d4a1a0cfeb355df5ed91f85d385fac88bd8d7c605b3578f9","src/include/catalog/pg_type.h":"8fb198749fd82b6c1818a3c18455f226f66116fcfeb3d4959c65ce3fda22802e"},"source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"},"sections":[],"signature":"bytea","sources":[{"label":"PostgreSQL 18 English manual","path":"datatype-binary.html","sha256":"0c03ec47b76e37888a3da7f5dcfd340128a5d356642a85185cc9ebe17856a904","url":"/docs/18/datatype-binary.html"},{"label":"Matching PostgreSQL source archive","sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"}]},"ManualEvidence":{"manual_path":"datatype-binary.html","release":{"channel":"stable","label":"18.6","major":"18","manual_sha256":{"arrays.html":"0e1d5c5a7b4a949d4439995f44f74ad4264e050d16eb9ad2a850fbaee04032df","catalog-pg-type.html":"ea9c9313bab8e92a7da18ebc50c7ff1f908dd80999a7e0ca3bbc82ba626c58d4","datatype-binary.html":"0c03ec47b76e37888a3da7f5dcfd340128a5d356642a85185cc9ebe17856a904","datatype-bit.html":"c49124aad561636c18080b9e09572fde7785a6b9eae86f5a33283f0fd6774c37","datatype-boolean.html":"b633f663e6c8276e7056287640c413aa79dbc15d5353cee0d41653d58d376956","datatype-character.html":"c73eebe413ea709a7792e4cfc3cfe9fb68cb496ebe83c3ebaa9d09f8c40d0f73","datatype-datetime.html":"e366275d8b13845bfa4ef0d68faa093e5f3ecb708a1ec870cbcbf7e425b85699","datatype-enum.html":"cab38e53222e30cc94b24de4b33634fd22d7c93f58ebcf35f646c9b8da78fae8","datatype-geometric.html":"0eb3053cfe7d6b0a4b5592c5d7af8d97cae527e87f063c5793413bcba5c14cd9","datatype-json.html":"650162a05b660146b500a205d523374d00aee117a6a6240d30262be51b6e33e5","datatype-money.html":"8b29c14b90679683ac5c472b59a0a7e2853f32cc7db43fab417b2697a6879964","datatype-net-types.html":"96846e641cc37727ddcd8b8a1aa0dbe33cd9787760a2b4efb0dcb9403d5be63f","datatype-numeric.html":"b74619f7ac2f1ca9f85c48073df78c33dd30e464e61baba6008634534edcb500","datatype-oid.html":"8b3360302225f08ae72716ce1804596de95b568e5d31f788cb4597427b28cc38","datatype-pg-lsn.html":"339172f5107cc7eb7139bec911277647219e92a532cebd0f3da0a5dacf8195af","datatype-pseudo.html":"c7cf0b8214304bd8702c95f2142671ae5f0d631f83717f9c07d9e1f2579961b4","datatype-textsearch.html":"4b15e05be8b49a71b28aea22f2c46d0dbf639a91e7b4fe129a4c737c6daad47c","datatype-uuid.html":"292b307b3223c6182bdba687e7f69e6dca9038430143ad79d56327f6ed4c3246","datatype-xml.html":"061fc2295b7b69be704f0a741b8decd10ad721059f871fb0243c669bb54d7822","datatype.html":"e581f67c74e42006289638c8659e9b338adbfd7f068bd8bf2b3be3880fcd2254","domains.html":"82d486973ccc35d14276627a67ac76b434452f23f9ed4d8aa3fbb01fdf285fc2","functions-info.html":"78ac80bf81da2e4f4a33f3b850faa86f0f58ec54a083d6c31da557907de0df87","rangetypes.html":"e4960abc7ce8e51d794f94f1e57b099d30b7f75dd7f2b23a960eef91f6291c33","rowtypes.html":"74f99e029c3a9edfd3e18810ba3c8cb66d3aada91eb67b86476560871e6617e9","sql-createdomain.html":"e94f927196de1b0ea1ce35cd4603c1f6f544439adcc0edf1c4222358e832245b"},"ref":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2","revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_files":{"doc/src/sgml/datatype.sgml":"86328daa77e20d81d222376ec0306d9841a17104e436c08d138eb763aefb3700","src/include/catalog/pg_am.dat":"b3cb86b102a42fb0024cbd99779c9897afb40d12a71f5cc5a0e5aee7ff2f9969","src/include/catalog/pg_am.h":"3426799df799f32163fcc0765f43dbdb5e88e626acf31284fef9fc6014b69d8e","src/include/catalog/pg_cast.dat":"97911281ca2c81917394ccb2ec13367e37c6801fd461d5e1a3d2f28b911b46b2","src/include/catalog/pg_cast.h":"de585c7df687d698e7d1d100dce8a794ac9da52414ea48169191019178c8f053","src/include/catalog/pg_opclass.dat":"4ee7d3619a6aa106e1c0db55de903931c7d11b1c60ba053a022519c55f8ee668","src/include/catalog/pg_opclass.h":"9c218537806c8ef0398302faaca7f91315dfc1198c48706cebffb479b68defaf","src/include/catalog/pg_operator.dat":"5d35b9b2ef5f9797cc815263927ef8a12367fedace53e828b4e8b320e2a7f703","src/include/catalog/pg_operator.h":"621b18cfffe102413d79b746ce7a10f77fc60fdd097bac34c22b31070d3ee3c4","src/include/catalog/pg_opfamily.dat":"3b694879027b858f2ecf1fa1152b7e30c6e15a216ba99c2384291c30e9d52311","src/include/catalog/pg_opfamily.h":"e1f5fc8aebd3042df847455bf66bf755f768c2aa8a9b03d22f7ec8563eba59c0","src/include/catalog/pg_proc.dat":"1f934ce80d460159dda137714374a35f9896315ea2476709cbb4da13b38ef95a","src/include/catalog/pg_proc.h":"f7d59f07c5b95e2f3c7141762a0f576e8a3af7581ba54c27537f4d500472bea5","src/include/catalog/pg_range.dat":"5c2271f8e89e9378d1887204e5785060b77405b5f0ff3e6c719250c9c1dcfcc4","src/include/catalog/pg_range.h":"45546d952b5181f989bd9234721897fc2b37005c8e49ce2ddc156f26974c3ca4","src/include/catalog/pg_type.dat":"5f5887b75677cba2d4a1a0cfeb355df5ed91f85d385fac88bd8d7c605b3578f9","src/include/catalog/pg_type.h":"8fb198749fd82b6c1818a3c18455f226f66116fcfeb3d4959c65ce3fda22802e"},"source_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f"},"sources":[{"label":"PostgreSQL 18 English manual","path":"datatype-binary.html","sha256":"0c03ec47b76e37888a3da7f5dcfd340128a5d356642a85185cc9ebe17856a904","url":"/docs/18/datatype-binary.html"},{"label":"Matching PostgreSQL source archive","sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"}]},"MeasuredEvidence":{}},"Text":{"Collection":"type","Key":"bytea","SourceDatabase":"center","Version":"18","Locale":"en","Title":"bytea","Summary":"binary data ( “ byte array ” )","BodyHTML":"\u003cdiv id=\"DATATYPE-BINARY\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch2\u003e8.4. Binary Data Types \u003c/h2\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\u003cp\u003eThe \u003ccode\u003ebytea\u003c/code\u003e data type allows storage of binary strings; see \u003ca href=\"/docs/18/datatype-binary.html#DATATYPE-BINARY-TABLE\" rel=\"nofollow\"\u003eTable 8.6\u003c/a\u003e.\u003c/p\u003e\n\u003cdiv id=\"DATATYPE-BINARY-TABLE\"\u003e\n\u003cp\u003e\u003cstrong\u003eTable 8.6. Binary Data Types\u003c/strong\u003e\u003c/p\u003e\n\u003cdiv\u003e\n\u003ctable\u003e\n\n\n\n\n\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eName\u003c/th\u003e\n\u003cth\u003eStorage Size\u003c/th\u003e\n\u003cth\u003eDescription\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003ebytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e1 or 4 bytes plus the actual binary string\u003c/td\u003e\n\u003ctd\u003evariable-length binary string\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003cbr\u003e\n\u003cp\u003eA binary string is a sequence of octets (or bytes). Binary strings are distinguished from character strings in two ways. First, binary strings specifically allow storing octets of value zero and other \u003cspan\u003e“\u003cspan\u003enon-printable\u003c/span\u003e”\u003c/span\u003e octets (usually, octets outside the decimal range 32 to 126). Character strings disallow zero octets, and also disallow any other octet values and sequences of octet values that are invalid according to the database\u0026#39;s selected character set encoding. Second, operations on binary strings process the actual bytes, whereas the processing of character strings depends on locale settings. In short, binary strings are appropriate for storing data that the programmer thinks of as \u003cspan\u003e“\u003cspan\u003eraw bytes\u003c/span\u003e”\u003c/span\u003e, whereas character strings are appropriate for storing text.\u003c/p\u003e\n\u003cp\u003eThe \u003ccode\u003ebytea\u003c/code\u003e type supports two formats for input and output: \u003cspan\u003e“\u003cspan\u003ehex\u003c/span\u003e”\u003c/span\u003e format and \u003cspan\u003ePostgreSQL\u003c/span\u003e\u0026#39;s historical \u003cspan\u003e“\u003cspan\u003eescape\u003c/span\u003e”\u003c/span\u003e format. Both of these are always accepted on input. The output format depends on the configuration parameter \u003ca href=\"/docs/18/runtime-config-client.html#GUC-BYTEA-OUTPUT\" rel=\"nofollow\"\u003ebytea_output\u003c/a\u003e; the default is hex. (Note that the hex format was introduced in \u003cspan\u003ePostgreSQL\u003c/span\u003e 9.0; earlier versions and some tools don\u0026#39;t understand it.)\u003c/p\u003e\n\u003cp\u003eThe SQL standard defines a different binary string type, called \u003ccode\u003eBLOB\u003c/code\u003e or \u003ccode\u003eBINARY LARGE OBJECT\u003c/code\u003e. The input format is different from \u003ccode\u003ebytea\u003c/code\u003e, but the provided functions and operators are mostly the same.\u003c/p\u003e\n\u003cdiv id=\"DATATYPE-BINARY-BYTEA-HEX-FORMAT\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3\u003e8.4.1. \u003ccode\u003ebytea\u003c/code\u003e Hex Format \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThe \u003cspan\u003e“\u003cspan\u003ehex\u003c/span\u003e”\u003c/span\u003e format encodes binary data as 2 hexadecimal digits per byte, most significant nibble first. The entire string is preceded by the sequence \u003ccode\u003e\\x\u003c/code\u003e (to distinguish it from the escape format). In some contexts, the initial backslash may need to be escaped by doubling it (see \u003ca href=\"/docs/18/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS\" rel=\"nofollow\"\u003eSection 4.1.2.1\u003c/a\u003e). For input, the hexadecimal digits can be either upper or lower case, and whitespace is permitted between digit pairs (but not within a digit pair nor in the starting \u003ccode\u003e\\x\u003c/code\u003e sequence). The hex format is compatible with a wide range of external applications and protocols, and it tends to be faster to convert than the escape format, so its use is preferred.\u003c/p\u003e\n\u003cp\u003eExample:\u003c/p\u003e\n\u003cpre\u003eSET bytea_output = \u0026#39;hex\u0026#39;;\n\nSELECT \u0026#39;\\xDEADBEEF\u0026#39;::bytea;\n   bytea\n------------\n \\xdeadbeef\n\u003c/pre\u003e\n\u003c/div\u003e\n\u003cdiv id=\"DATATYPE-BINARY-BYTEA-ESCAPE-FORMAT\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3\u003e8.4.2. \u003ccode\u003ebytea\u003c/code\u003e Escape Format \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThe \u003cspan\u003e“\u003cspan\u003eescape\u003c/span\u003e”\u003c/span\u003e format is the traditional \u003cspan\u003ePostgreSQL\u003c/span\u003e format for the \u003ccode\u003ebytea\u003c/code\u003e type. It takes the approach of representing a binary string as a sequence of ASCII characters, while converting those bytes that cannot be represented as an ASCII character into special escape sequences. If, from the point of view of the application, representing bytes as characters makes sense, then this representation can be convenient. But in practice it is usually confusing because it fuzzes up the distinction between binary strings and character strings, and also the particular escape mechanism that was chosen is somewhat unwieldy. Therefore, this format should probably be avoided for most new applications.\u003c/p\u003e\n\u003cp\u003eWhen entering \u003ccode\u003ebytea\u003c/code\u003e values in escape format, octets of certain values \u003cspan\u003e\u003cem\u003emust\u003c/em\u003e\u003c/span\u003e be escaped, while all octet values \u003cspan\u003e\u003cem\u003ecan\u003c/em\u003e\u003c/span\u003e be escaped. In general, to escape an octet, convert it into its three-digit octal value and precede it by a backslash. Backslash itself (octet decimal value 92) can alternatively be represented by double backslashes. \u003ca href=\"/docs/18/datatype-binary.html#DATATYPE-BINARY-SQLESC\" rel=\"nofollow\"\u003eTable 8.7\u003c/a\u003e shows the characters that must be escaped, and gives the alternative escape sequences where applicable.\u003c/p\u003e\n\u003cdiv id=\"DATATYPE-BINARY-SQLESC\"\u003e\n\u003cp\u003e\u003cstrong\u003eTable 8.7. \u003ccode\u003ebytea\u003c/code\u003e Literal Escaped Octets\u003c/strong\u003e\u003c/p\u003e\n\u003cdiv\u003e\n\u003ctable\u003e\n\n\n\n\n\n\n\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eDecimal Octet Value\u003c/th\u003e\n\u003cth\u003eDescription\u003c/th\u003e\n\u003cth\u003eEscaped Input Representation\u003c/th\u003e\n\u003cth\u003eExample\u003c/th\u003e\n\u003cth\u003eHex Representation\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003e0\u003c/td\u003e\n\u003ctd\u003ezero octet\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003e\u0026#39;\\000\u0026#39;\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003e\u0026#39;\\000\u0026#39;::bytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003e\\x00\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e39\u003c/td\u003e\n\u003ctd\u003esingle quote\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003e\u0026#39;\u0026#39;\u0026#39;\u0026#39;\u003c/code\u003e or \u003ccode\u003e\u0026#39;\\047\u0026#39;\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003e\u0026#39;\u0026#39;\u0026#39;\u0026#39;::bytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003e\\x27\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e92\u003c/td\u003e\n\u003ctd\u003ebackslash\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003e\u0026#39;\\\\\u0026#39;\u003c/code\u003e or \u003ccode\u003e\u0026#39;\\134\u0026#39;\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003e\u0026#39;\\\\\u0026#39;::bytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003e\\x5c\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e0 to 31 and 127 to 255\u003c/td\u003e\n\u003ctd\u003e\u003cspan\u003e“\u003cspan\u003enon-printable\u003c/span\u003e”\u003c/span\u003e octets\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003e\u0026#39;\\\u003cem\u003e\u003ccode\u003exxx\u0026#39;\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e (octal value)\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003e\u0026#39;\\001\u0026#39;::bytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003e\\x01\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003cbr\u003e\n\u003cp\u003eThe requirement to escape \u003cspan\u003e\u003cem\u003enon-printable\u003c/em\u003e\u003c/span\u003e octets varies depending on locale settings. In some instances you can get away with leaving them unescaped.\u003c/p\u003e\n\u003cp\u003eThe reason that single quotes must be doubled, as shown in \u003ca href=\"/docs/18/datatype-binary.html#DATATYPE-BINARY-SQLESC\" rel=\"nofollow\"\u003eTable 8.7\u003c/a\u003e, is that this is true for any string literal in an SQL command. The generic string-literal parser consumes the outermost single quotes and reduces any pair of single quotes to one data character. What the \u003ccode\u003ebytea\u003c/code\u003e input function sees is just one single quote, which it treats as a plain data character. However, the \u003ccode\u003ebytea\u003c/code\u003e input function treats backslashes as special, and the other behaviors shown in \u003ca href=\"/docs/18/datatype-binary.html#DATATYPE-BINARY-SQLESC\" rel=\"nofollow\"\u003eTable 8.7\u003c/a\u003e are implemented by that function.\u003c/p\u003e\n\u003cp\u003eIn some contexts, backslashes must be doubled compared to what is shown above, because the generic string-literal parser will also reduce pairs of backslashes to one data character; see \u003ca href=\"/docs/18/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS\" rel=\"nofollow\"\u003eSection 4.1.2.1\u003c/a\u003e.\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003eBytea\u003c/code\u003e octets are output in \u003ccode\u003ehex\u003c/code\u003e format by default. If you change \u003ca href=\"/docs/18/runtime-config-client.html#GUC-BYTEA-OUTPUT\" rel=\"nofollow\"\u003ebytea_output\u003c/a\u003e to \u003ccode\u003eescape\u003c/code\u003e, \u003cspan\u003e“\u003cspan\u003enon-printable\u003c/span\u003e”\u003c/span\u003e octets are converted to their equivalent three-digit octal value and preceded by one backslash. Most \u003cspan\u003e“\u003cspan\u003eprintable\u003c/span\u003e”\u003c/span\u003e octets are output by their standard representation in the client character set, e.g.:\u003c/p\u003e\n\u003cpre\u003eSET bytea_output = \u0026#39;escape\u0026#39;;\n\nSELECT \u0026#39;abc \\153\\154\\155 \\052\\251\\124\u0026#39;::bytea;\n     bytea\n----------------\n abc klm *\\251T\n\u003c/pre\u003e\n\u003cp\u003eThe octet with decimal value 92 (backslash) is doubled in the output. Details are in \u003ca href=\"/docs/18/datatype-binary.html#DATATYPE-BINARY-RESESC\" rel=\"nofollow\"\u003eTable 8.8\u003c/a\u003e.\u003c/p\u003e\n\u003cdiv id=\"DATATYPE-BINARY-RESESC\"\u003e\n\u003cp\u003e\u003cstrong\u003eTable 8.8. \u003ccode\u003ebytea\u003c/code\u003e Output Escaped Octets\u003c/strong\u003e\u003c/p\u003e\n\u003cdiv\u003e\n\u003ctable\u003e\n\n\n\n\n\n\n\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eDecimal Octet Value\u003c/th\u003e\n\u003cth\u003eDescription\u003c/th\u003e\n\u003cth\u003eEscaped Output Representation\u003c/th\u003e\n\u003cth\u003eExample\u003c/th\u003e\n\u003cth\u003eOutput Result\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003e92\u003c/td\u003e\n\u003ctd\u003ebackslash\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003e\\\\\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003e\u0026#39;\\134\u0026#39;::bytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003e\\\\\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e0 to 31 and 127 to 255\u003c/td\u003e\n\u003ctd\u003e\u003cspan\u003e“\u003cspan\u003enon-printable\u003c/span\u003e”\u003c/span\u003e octets\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003e\\\u003cem\u003e\u003ccode\u003exxx\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e (octal value)\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003e\u0026#39;\\001\u0026#39;::bytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003e\\001\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e32 to 126\u003c/td\u003e\n\u003ctd\u003e\u003cspan\u003e“\u003cspan\u003eprintable\u003c/span\u003e”\u003c/span\u003e octets\u003c/td\u003e\n\u003ctd\u003eclient character set representation\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003e\u0026#39;\\176\u0026#39;::bytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003e~\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003cbr\u003e\n\u003cp\u003eDepending on the front end to \u003cspan\u003ePostgreSQL\u003c/span\u003e you use, you might have additional work to do in terms of escaping and unescaping \u003ccode\u003ebytea\u003c/code\u003e strings. For example, you might also have to escape line feeds and carriage returns if your interface automatically translates these.\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e","SourceRevision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","ContentHash":"f129648b2cc91f4a54a77f2243dfb6fd78c9e268498b0a6d60a65ed683c2b3f4","Payload":{"description":["binary data ( “ byte array ” )"],"manual_html":"\u003cdiv class=\"sect1\" id=\"DATATYPE-BINARY\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch2 class=\"title\"\u003e8.4. Binary Data Types \u003c/h2\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\n\u003cp\u003eThe \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e data type allows storage of binary strings; see \u003ca class=\"xref\" href=\"/docs/18/datatype-binary.html#DATATYPE-BINARY-TABLE\" title=\"Table 8.6. Binary Data Types\"\u003eTable 8.6\u003c/a\u003e.\u003c/p\u003e\n\u003cdiv class=\"table\" id=\"DATATYPE-BINARY-TABLE\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eTable 8.6. Binary Data Types\u003c/strong\u003e\u003c/p\u003e\n\u003cdiv class=\"table-contents\"\u003e\n\u003ctable class=\"table\"\u003e\n\n\n\n\n\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eName\u003c/th\u003e\n\u003cth\u003eStorage Size\u003c/th\u003e\n\u003cth\u003eDescription\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode class=\"type\"\u003ebytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e1 or 4 bytes plus the actual binary string\u003c/td\u003e\n\u003ctd\u003evariable-length binary string\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003cbr class=\"table-break\"\u003e\n\u003cp\u003eA binary string is a sequence of octets (or bytes). Binary strings are distinguished from character strings in two ways. First, binary strings specifically allow storing octets of value zero and other \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003enon-printable\u003c/span\u003e”\u003c/span\u003e octets (usually, octets outside the decimal range 32 to 126). Character strings disallow zero octets, and also disallow any other octet values and sequences of octet values that are invalid according to the database's selected character set encoding. Second, operations on binary strings process the actual bytes, whereas the processing of character strings depends on locale settings. In short, binary strings are appropriate for storing data that the programmer thinks of as \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003eraw bytes\u003c/span\u003e”\u003c/span\u003e, whereas character strings are appropriate for storing text.\u003c/p\u003e\n\u003cp\u003eThe \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e type supports two formats for input and output: \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003ehex\u003c/span\u003e”\u003c/span\u003e format and \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e's historical \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003eescape\u003c/span\u003e”\u003c/span\u003e format. Both of these are always accepted on input. The output format depends on the configuration parameter \u003ca class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-BYTEA-OUTPUT\"\u003ebytea_output\u003c/a\u003e; the default is hex. (Note that the hex format was introduced in \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 9.0; earlier versions and some tools don't understand it.)\u003c/p\u003e\n\u003cp\u003eThe SQL standard defines a different binary string type, called \u003ccode class=\"type\"\u003eBLOB\u003c/code\u003e or \u003ccode class=\"type\"\u003eBINARY LARGE OBJECT\u003c/code\u003e. The input format is different from \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e, but the provided functions and operators are mostly the same.\u003c/p\u003e\n\u003cdiv class=\"sect2\" id=\"DATATYPE-BINARY-BYTEA-HEX-FORMAT\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003e8.4.1. \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e Hex Format \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThe \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003ehex\u003c/span\u003e”\u003c/span\u003e format encodes binary data as 2 hexadecimal digits per byte, most significant nibble first. The entire string is preceded by the sequence \u003ccode class=\"literal\"\u003e\\x\u003c/code\u003e (to distinguish it from the escape format). In some contexts, the initial backslash may need to be escaped by doubling it (see \u003ca class=\"xref\" href=\"/docs/18/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS\" title=\"4.1.2.1. String Constants\"\u003eSection 4.1.2.1\u003c/a\u003e). For input, the hexadecimal digits can be either upper or lower case, and whitespace is permitted between digit pairs (but not within a digit pair nor in the starting \u003ccode class=\"literal\"\u003e\\x\u003c/code\u003e sequence). The hex format is compatible with a wide range of external applications and protocols, and it tends to be faster to convert than the escape format, so its use is preferred.\u003c/p\u003e\n\u003cp\u003eExample:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003eSET bytea_output = 'hex';\n\nSELECT '\\xDEADBEEF'::bytea;\n   bytea\n------------\n \\xdeadbeef\n\u003c/pre\u003e\n\u003c/div\u003e\n\u003cdiv class=\"sect2\" id=\"DATATYPE-BINARY-BYTEA-ESCAPE-FORMAT\"\u003e\n\u003cdiv class=\"titlepage\"\u003e\n\u003cdiv\u003e\n\u003cdiv\u003e\n\u003ch3 class=\"title\"\u003e8.4.2. \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e Escape Format \u003c/h3\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003c/div\u003e\n\u003cp\u003eThe \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003eescape\u003c/span\u003e”\u003c/span\u003e format is the traditional \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e format for the \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e type. It takes the approach of representing a binary string as a sequence of ASCII characters, while converting those bytes that cannot be represented as an ASCII character into special escape sequences. If, from the point of view of the application, representing bytes as characters makes sense, then this representation can be convenient. But in practice it is usually confusing because it fuzzes up the distinction between binary strings and character strings, and also the particular escape mechanism that was chosen is somewhat unwieldy. Therefore, this format should probably be avoided for most new applications.\u003c/p\u003e\n\u003cp\u003eWhen entering \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e values in escape format, octets of certain values \u003cspan class=\"emphasis\"\u003e\u003cem\u003emust\u003c/em\u003e\u003c/span\u003e be escaped, while all octet values \u003cspan class=\"emphasis\"\u003e\u003cem\u003ecan\u003c/em\u003e\u003c/span\u003e be escaped. In general, to escape an octet, convert it into its three-digit octal value and precede it by a backslash. Backslash itself (octet decimal value 92) can alternatively be represented by double backslashes. \u003ca class=\"xref\" href=\"/docs/18/datatype-binary.html#DATATYPE-BINARY-SQLESC\" title=\"Table 8.7. bytea Literal Escaped Octets\"\u003eTable 8.7\u003c/a\u003e shows the characters that must be escaped, and gives the alternative escape sequences where applicable.\u003c/p\u003e\n\u003cdiv class=\"table\" id=\"DATATYPE-BINARY-SQLESC\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eTable 8.7. \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e Literal Escaped Octets\u003c/strong\u003e\u003c/p\u003e\n\u003cdiv class=\"table-contents\"\u003e\n\u003ctable class=\"table\"\u003e\n\n\n\n\n\n\n\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eDecimal Octet Value\u003c/th\u003e\n\u003cth\u003eDescription\u003c/th\u003e\n\u003cth\u003eEscaped Input Representation\u003c/th\u003e\n\u003cth\u003eExample\u003c/th\u003e\n\u003cth\u003eHex Representation\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003e0\u003c/td\u003e\n\u003ctd\u003ezero octet\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e'\\000'\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e'\\000'::bytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e\\x00\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e39\u003c/td\u003e\n\u003ctd\u003esingle quote\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e''''\u003c/code\u003e or \u003ccode class=\"literal\"\u003e'\\047'\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e''''::bytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e\\x27\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e92\u003c/td\u003e\n\u003ctd\u003ebackslash\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e'\\\\'\u003c/code\u003e or \u003ccode class=\"literal\"\u003e'\\134'\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e'\\\\'::bytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e\\x5c\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e0 to 31 and 127 to 255\u003c/td\u003e\n\u003ctd\u003e\u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003enon-printable\u003c/span\u003e”\u003c/span\u003e octets\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e'\\\u003cem class=\"replaceable\"\u003e\u003ccode\u003exxx'\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e (octal value)\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e'\\001'::bytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e\\x01\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003cbr class=\"table-break\"\u003e\n\u003cp\u003eThe requirement to escape \u003cspan class=\"emphasis\"\u003e\u003cem\u003enon-printable\u003c/em\u003e\u003c/span\u003e octets varies depending on locale settings. In some instances you can get away with leaving them unescaped.\u003c/p\u003e\n\u003cp\u003eThe reason that single quotes must be doubled, as shown in \u003ca class=\"xref\" href=\"/docs/18/datatype-binary.html#DATATYPE-BINARY-SQLESC\" title=\"Table 8.7. bytea Literal Escaped Octets\"\u003eTable 8.7\u003c/a\u003e, is that this is true for any string literal in an SQL command. The generic string-literal parser consumes the outermost single quotes and reduces any pair of single quotes to one data character. What the \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e input function sees is just one single quote, which it treats as a plain data character. However, the \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e input function treats backslashes as special, and the other behaviors shown in \u003ca class=\"xref\" href=\"/docs/18/datatype-binary.html#DATATYPE-BINARY-SQLESC\" title=\"Table 8.7. bytea Literal Escaped Octets\"\u003eTable 8.7\u003c/a\u003e are implemented by that function.\u003c/p\u003e\n\u003cp\u003eIn some contexts, backslashes must be doubled compared to what is shown above, because the generic string-literal parser will also reduce pairs of backslashes to one data character; see \u003ca class=\"xref\" href=\"/docs/18/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS\" title=\"4.1.2.1. String Constants\"\u003eSection 4.1.2.1\u003c/a\u003e.\u003c/p\u003e\n\u003cp\u003e\u003ccode class=\"type\"\u003eBytea\u003c/code\u003e octets are output in \u003ccode class=\"literal\"\u003ehex\u003c/code\u003e format by default. If you change \u003ca class=\"xref\" href=\"/docs/18/runtime-config-client.html#GUC-BYTEA-OUTPUT\"\u003ebytea_output\u003c/a\u003e to \u003ccode class=\"literal\"\u003eescape\u003c/code\u003e, \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003enon-printable\u003c/span\u003e”\u003c/span\u003e octets are converted to their equivalent three-digit octal value and preceded by one backslash. Most \u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003eprintable\u003c/span\u003e”\u003c/span\u003e octets are output by their standard representation in the client character set, e.g.:\u003c/p\u003e\n\u003cpre class=\"programlisting\"\u003eSET bytea_output = 'escape';\n\nSELECT 'abc \\153\\154\\155 \\052\\251\\124'::bytea;\n     bytea\n----------------\n abc klm *\\251T\n\u003c/pre\u003e\n\u003cp\u003eThe octet with decimal value 92 (backslash) is doubled in the output. Details are in \u003ca class=\"xref\" href=\"/docs/18/datatype-binary.html#DATATYPE-BINARY-RESESC\" title=\"Table 8.8. bytea Output Escaped Octets\"\u003eTable 8.8\u003c/a\u003e.\u003c/p\u003e\n\u003cdiv class=\"table\" id=\"DATATYPE-BINARY-RESESC\"\u003e\n\u003cp class=\"title\"\u003e\u003cstrong\u003eTable 8.8. \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e Output Escaped Octets\u003c/strong\u003e\u003c/p\u003e\n\u003cdiv class=\"table-contents\"\u003e\n\u003ctable class=\"table\"\u003e\n\n\n\n\n\n\n\n\u003cthead\u003e\n\u003ctr\u003e\n\u003cth\u003eDecimal Octet Value\u003c/th\u003e\n\u003cth\u003eDescription\u003c/th\u003e\n\u003cth\u003eEscaped Output Representation\u003c/th\u003e\n\u003cth\u003eExample\u003c/th\u003e\n\u003cth\u003eOutput Result\u003c/th\u003e\n\u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n\u003ctr\u003e\n\u003ctd\u003e92\u003c/td\u003e\n\u003ctd\u003ebackslash\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e\\\\\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e'\\134'::bytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e\\\\\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e0 to 31 and 127 to 255\u003c/td\u003e\n\u003ctd\u003e\u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003enon-printable\u003c/span\u003e”\u003c/span\u003e octets\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e\\\u003cem class=\"replaceable\"\u003e\u003ccode\u003exxx\u003c/code\u003e\u003c/em\u003e\u003c/code\u003e (octal value)\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e'\\001'::bytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e\\001\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e32 to 126\u003c/td\u003e\n\u003ctd\u003e\u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003eprintable\u003c/span\u003e”\u003c/span\u003e octets\u003c/td\u003e\n\u003ctd\u003eclient character set representation\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e'\\176'::bytea\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode class=\"literal\"\u003e~\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003cbr class=\"table-break\"\u003e\n\u003cp\u003eDepending on the front end to \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e you use, you might have additional work to do in terms of escaping and unescaping \u003ccode class=\"type\"\u003ebytea\u003c/code\u003e strings. For example, you might also have to escape line feeds and carriage returns if your interface automatically translates these.\u003c/p\u003e\n\u003c/div\u003e\n\u003c/div\u003e","related":[{"label":"pg_type catalog","url":"/wiki/catalog/pg_type/?v=18"},{"label":"pg_cast catalog","url":"/wiki/catalog/pg_cast/?v=18"},{"label":"pg_operator catalog","url":"/wiki/catalog/pg_operator/?v=18"},{"label":"pg_opclass catalog","url":"/wiki/catalog/pg_opclass/?v=18"},{"label":"Arrays","url":"/wiki/type/arrays/?v=18"},{"label":"brin index access method","url":"/wiki/indexam/brin/?v=18"},{"label":"btree index access method","url":"/wiki/indexam/btree/?v=18"},{"label":"hash index access method","url":"/wiki/indexam/hash/?v=18"}],"sections":[]}},"RequestedLocale":"zh-Hans","Fallback":true,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
