Postgresql流水帐(第一天): SQL Syntax
4.1. Lexical Structure (SQL命令的结构or组成)
关键字:SELECT, INSERT, UPDATE, DELETE
带双引号的标识符(delimited identifier or quoted identifier):
加了双引号后,关键字就可以作为 标识符 如表名或字段名, 如 select * from "select" where "insert"=2
UPDATE MYTABLE SET a=5 等价于 update myTable set a =5
C语言风格的字符串常量:转义字符…, 牵扯到数据库系统的字符集,两者要一致
Backslash Escape Sequence | Interpretation |
\b | backspace |
\f | form feed |
\n | newline |
\r | carriage return |
\t | tab |
\o, \oo, \ooo (o = 0 - 7) | octal byte value |
\xh, \xhh (h = 0 - 9, A - F) | hexadecimal byte value |
\uxxxx, \Uxxxxxxxx (x = 0 - 9, A - F) | 16 or 32-bit hexadecimal Unicode character value |
Dollar-quoted String Constants
RETURN ($1 ~ $q$[\t\r\n\v\\]$q$);
B'1001', 有点儿像python里的 bytes b'hello'
+ - * / < > = ~ ! @ # % ^ & | ` ?
-- This is a standard SQL comment
* with nesting: /* nested block comment */
Operator/Element | Associativity | Description |
. | left | table/column name separator |
:: | left | PostgreSQL-style typecast |
[ ] | left | array element selection |
+ - | right | unary plus, unary minus |
^ | left | exponentiation |
* / % | left | multiplication, division, modulo |
+ - | left | addition, subtraction |
(any other operator) | left | all other native and user-defined operators |
BETWEEN IN LIKE ILIKE SIMILAR |
| range containment, set membership, string matching |
< > = <= >= <> |
| comparison operators |
IS ISNULL NOTNULL |
| IS TRUE, IS FALSE, IS NULL, IS DISTINCT FROM, etc |
NOT | right | logical negation |
AND | left | logical conjunction |
OR | left | logical disjunction |