PostgreSQL 语法
默认情况下 PostgreSQL 安装完成后,自带了一个命令行工具 SQL Shell(psql)。
Linux 系统可以直接切换到 postgres 用户来开启命令行工具:
# sudo -i -u postgres
Windows 系统一般在它的安装目录下:
Program Files → PostgreSQL 11.3 → SQL Shell(psql)
Mac OS 我们直接搜索就可以了找到:

进入命令行工具,我们可以使用 \help 来查看各个命令的语法 :
postgres-# \help <command_name>
例如,我们查看下 select 语句的语法:
postgres=# \help SELECT
Command: SELECT
Description: retrieve rows from a table or view
Syntax:
[ WITH [ RECURSIVE ] with_query [, ...] ]
SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]
[ * | expression [ [ AS ] output_name ] [, ...] ]
[ FROM from_item [, ...] ]
[ WHERE condition ]
[ GROUP BY grouping_element [, ...] ]
[ HAVING condition [, ...] ]
[ WINDOW window_name AS ( window_definition ) [, ...] ]
[ { UNION | INTERSECT | EXCEPT } [ ALL | DISTINCT ] select ]
[ ORDER BY expression [ ASC | DESC | USING operator ] [ NULLS { FIRST | LAST } ] [, ...] ]
[ LIMIT { count | ALL } ]
[ OFFSET start [ ROW | ROWS ] ]
[ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY ]
[ FOR { UPDATE | NO KEY UPDATE | SHARE | KEY SHARE } [ OF table_name [, ...] ] [ NOWAIT | SKIP LOCKED ] [...] ]
from_item 可以是以下选项之一:
[ ONLY ] table_name [ * ] [ [ AS ] alias [ ( column_alias [, ...] ) ] ]