8.4.2. bytea Escape Format
8.4.2.
bytea
Escape Format
8.4.2.bytea escape格式
The “escape” format is the traditional PostgreSQL format for the
bytea
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.
“escape”格式是
PostgreSQL中
bytea型別的傳統格式。它採用將二進位制字串表示為ASCII字元序列的方法,同時將那些無法表示為ASCII字元的位元組轉換為特殊的轉義序列。如果從應用程式的角度來看,將位元組表示為字元是有意義的,那麼這種表示方式將很方便。但實際上,它通常令人困惑,因為它模糊了二進位制字串和字串之間的區別,並且所選擇的特殊轉義機制有些笨拙,因此,對於大多數新應用程式,應避免使用這種格式。
When entering
bytea
values in escape format, octets of certain values
must
be escaped, while all
octet values
can
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. Table 8.7 shows the characters that must be escaped, and gives the alternative
escape sequences where applicable.
在以escape格式輸入bytea值時,必須對某些值的八位位元組進行轉義,也可對所有八位位元組值都進行轉義。通常,要轉義八位位元組,需先將其轉換為三位數的八進位制值,並在其前加反斜槓。 反斜槓本身(八位位元組的十進位制值92)也可以用雙反斜槓表示。 表8.7顯示了必須轉義的字元,並給出了相適應的替代轉義序列。
The requirement to escape
non-printable
octets varies depending on locale settings. In some instances
you can get away with leaving them unescaped.
對不可列印的八位位元組進行轉義的要求取決於語言環境設定。在某些情況下,可以無需轉義。
The reason that single quotes must be doubled, as shown in Table 8.7, is that this is true for any string
literal in a 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
bytea
input function sees is just
one single quote, which it treats as a plain data character. However, the
bytea
input function treats
backslashes as special, and the other behaviors shown in Table 8.7 are implemented by that function.
如表8.7所示,單引號必須寫兩次。通用字串文字解析器使用最外面的單引號,並將任何一對單引號都簡化為一個資料字元。bytea輸入函式看到的只是一個單引號,它將其視為純資料字元。 但是,bytea輸入函式將反斜槓視為特殊字元,表8.7中所示的其他行為由該函式實現。
In 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 Section 4.1.2.1.
Bytea
octets are output in
hex
format by default. If you change bytea_output to
escape
, “nonprintable”
octets are converted to their equivalent three-digit octal value and preceded by one backslash.
Most “printable” octets are output by their standard representation in the client character set, e.g.:
預設,bytea位元組以十六進位制格式輸出。如果將bytea_output更改為escape,則``不可列印的''八位位組將轉換為等效的三位數八進位制值並以一個反斜槓開頭。大多數``可列印的''八位位組均以其在客戶端字符集中的標準表示形式輸出,例如:
SET bytea_output = 'escape';
SELECT 'abc \153\154\155 \052\251\124'::bytea;
bytea
----------------
abc klm *\251T
The octet with decimal value 92 (backslash) is doubled in the output. Details are in Table 8.8.
十進位制值92(反斜槓)的八位位元組
在輸出中為兩個反斜槓
。 詳情參見表8.8。
Depending on the front end to PostgreSQL you use, you might have additional work to do in terms of
escaping and unescaping
bytea
strings. For example, you might also have to escape line feeds and
carriage returns if your interface automatically translates these.
根據所使用的PostgreSQL的前端,在轉義和非轉義bytea字串方面,您可能還需要做其他工作。例如,如果您的介面自動翻譯了換行符和回車符,則可能還必須轉義它們。
相關文章
- JavaScript escape()JavaScript
- escape in ABAP and JavaScriptJavaScript
- MySql escape如何使用MySql
- Format and un-format money/currency in JavaScriptORMJavaScript
- mysql 的Escape轉義字串MySql字串
- Json formatJSONORM
- 求助:TypeError: unsupported format string passed to NoneType.__format__ErrorORMNone
- mysql 的Escape跳脫字元串MySql字元
- set excel formatExcelORM
- 狀壓 + 網路流 -- Escape HDU - 3605
- underscore 系列之字元實體與 _.escape字元
- 問題解決:TypeError: unsupported format string passed to NoneType.__format__ErrorORMNone
- [Ruby]format xml with RubyORMXML
- oracle工具 awr formatOracleORM
- vim Google style formatGoORM
- iOS Jailbreak Principles - Undecimus 分析(一)Escape from SandboxiOSAI
- MySql escape的使用案例詳解獗鰳MySql
- Go語言之變數逃逸(Escape Analysis)分析Go變數
- jQuery Validate的format()用法jQueryORM
- 針對python錯誤 format()PythonORM
- JAVA中String format的用法JavaORM
- [#181024][PAT Practice] A+B FormatORM
- 電腦hold escape key to prevent startlsback怎麼處理?TLS
- 請說說escape、encodeURI、decodeURI、encodeURIComponent和decodeURIComponent的區別?
- 善用 Format 來格式化字串ORM字串
- Clang-format格式標準化ORM
- libheif is an HEIF and AVIF file format decoder and encoderORM
- OAF export data from VO in xlsx formatExportORM
- python中zip和format的使用PythonORM
- python str.format高階用法PythonORM
- SQLSTATE [22007]: Invalid datetime format: 1292 IncorrectSQLORM
- PAT:1001 A+B Format (20分)ORM
- Conversion to Dalvik format failed: Unable to execute dexORMAI
- String.format()的詳細用法ORM
- 連結字串String.prototype.format字串ORM
- oracle data Format Models---二(轉)OracleORM
- 12.2、python內建函式—formatPython函式ORM
- Delphi Format 格式化數字ORM