Postgresql 中文操作指南
Notes
在典型用法中, string 是对包含动态构造的 SQL 语句的字符串的主机变量引用。文字字符串的情况没有什么用,你不仅可以通过编写直接的 SQL PREPARE 语句来解决。
In typical usage, the string is a host variable reference to a string containing a dynamically-constructed SQL statement. The case of a literal string is not very useful; you might as well just write a direct SQL PREPARE statement.
如果你确实使用文字字符串,请记住你可能希望包含在 SQL 语句中的任何双引号必须写成八进制转义字符 ( \042 ),而不是通常的 C 惯用法 \" 。这是因为字符串位于 EXEC SQL 部分中,因此 ECPG 词法分析器根据 SQL 规则而不是 C 规则对其进行解析。任何嵌入的反斜杠都会根据 C 规则得到处理;但 \" 会引起立即的语法错误,因为它被视为结束的文字。
If you do use a literal string, keep in mind that any double quotes you might wish to include in the SQL statement must be written as octal escapes (\042) not the usual C idiom \". This is because the string is inside an EXEC SQL section, so the ECPG lexer parses it according to SQL rules not C rules. Any embedded backslashes will later be handled according to C rules; but \" causes an immediate syntax error because it is seen as ending the literal.