如何學習PostgreSQL SQL文法
我們可以利用psql命令來查詢sql文法。切換到PostgreSQL使用者下,
[doctor@localhost ~]$ su - postgres
密碼:
su: 評鑑故障
[doctor@localhost ~]$ su - postgres
密碼:
-bash-4.3$ bash
bash-4.3$ psql
psql (9.4.2)
輸入 "help" 來擷取協助資訊.
postgres=#
postgres=# help
您正在使用psql, 這是一種用於訪問PostgreSQL的命令列介面
鍵入: \copyright 顯示發行條款
\h 顯示 SQL 命令的說明
\? 顯示 pgsql 命令的說明
\g 或者以分號(;)結尾以執行查詢
\q 退出
postgres=#
\h 命令就是我們用來學習sql文法的命令。
postgres=# \h
可用的說明:
ABORT DEALLOCATE
ALTER AGGREGATE DECLARE
ALTER COLLATION DELETE
ALTER CONVERSION DISCARD
ALTER DATABASE DO
ALTER DEFAULT PRIVILEGES DROP AGGREGATE
ALTER DOMAIN DROP CAST
ALTER EVENT TRIGGER DROP COLLATION
ALTER EXTENSION DROP CONVERSION
ALTER FOREIGN DATA WRAPPER DROP DATABASE
ALTER FOREIGN TABLE DROP DOMAIN
ALTER FUNCTION DROP EVENT TRIGGER
ALTER GROUP DROP EXTENSION
ALTER INDEX DROP FOREIGN DATA WRAPPER
ALTER LANGUAGE DROP FOREIGN TABLE
ALTER LARGE OBJECT DROP FUNCTION
ALTER MATERIALIZED VIEW DROP GROUP
ALTER OPERATOR DROP INDEX
ALTER OPERATOR CLASS DROP LANGUAGE
ALTER OPERATOR FAMILY DROP MATERIALIZED VIEW
ALTER ROLE DROP OPERATOR
ALTER RULE DROP OPERATOR CLASS
postgres=# \h select
命令: SELECT
描述: 從資料表或視觀表讀取資料
文法:
[ WITH [ RECURSIVE ] with查詢語句(with_query) [, ...] ]
SELECT [ ALL | DISTINCT [ ON ( 運算式 [, ...] ) ] ]
[ * | 運算式 [ [ AS ] 輸出名稱 ] [, ...] ]
[ FROM from列表中項 [, ...] ]
[ WHERE 條件 ]
[ GROUP BY 運算式 [, ...] ]
[ HAVING 條件 [, ...] ]
[ WINDOW 視窗名稱 AS ( 視窗定義 ) [, ...] ]
[ { UNION | INTERSECT | EXCEPT } [ ALL | DISTINCT ] 查詢 ]
[ ORDER BY 運算式 [ ASC | DESC | USING 運運算元 ] [ NULLS { FIRST | LAST } ] [
, ...] ]
[ LIMIT { 查詢所用返回記錄的最大數量 | ALL } ]
[ OFFSET 起始值 [ ROW | ROWS ] ]
[ FETCH { FIRST | NEXT } [ 查詢所用返回記錄的最大數量 ] { ROW | ROWS } ONLY
]
[ FOR { UPDATE | NO KEY UPDATE | SHARE | KEY SHARE } [ OF 表名 [, ...] ] [ N
OWAIT ] [...] ]
from 列表中的項可以是下列內容之一
[ ONLY ] 表名 [ * ] [ [ AS ] 化名 [ ( 列的化名 [, ...] ) ] ]
[ LATERAL ] ( 查詢 ) [ AS ] 化名 [ ( 列的化名 [, ...] ) ]
WITH查詢語句名稱(with_query_name) [ [ AS ] 化名 [ ( 列的化名 [, ...] ) ] ]
[ LATERAL ] 函數名稱 ( [ 參數 [, ...] ] )
[ WITH ORDINALITY ] [ [ AS ] 化名 [ ( 列的化名 [, ...] ) ] ]
[ LATERAL ] 函數名稱 ( [ 參數 [, ...] ] ) [ AS ] 化名 ( 列定義 [, ...] )
[ LATERAL ] 函數名稱 ( [ 參數 [, ...] ] ) AS ( 列定義 [, ...] )
[ LATERAL ] ROWS FROM( 函數名稱 ( [ 參數 [, ...] ] ) [ AS ( 列定義 [, ...] )
] [, ...] )
[ WITH ORDINALITY ] [ [ AS ] 化名 [ ( 列的化名 [, ...] ) ] ]
from列表中項 [ NATURAL ] 串連操作的類型 from列表中項 [ ON 用串連操作的條件 |
USING ( 用於串連操作的列 [, ...] ) ]
with查詢語句是:
WITH查詢語句名稱(with_query_name) [ ( 列名稱 [, ...] ) ] AS ( 查詢 | 值 | in
sert | update | delete )
TABLE [ ONLY ] 表名 [ * ]
postgres=#
看這命令對於學習sql文法很有用。
------------------------------------華麗麗的分割線------------------------------------
CentOS 6.3環境下yum安裝PostgreSQL 9.3
PostgreSQL緩衝詳述
Windows平台編譯 PostgreSQL
Ubuntu下LAPP(Linux+Apache+PostgreSQL+PHP)環境的配置與安裝
Ubuntu上的phppgAdmin安裝及配置
CentOS平台下安裝PostgreSQL9.3
PostgreSQL配置Streaming Replication叢集
如何在CentOS 7/6.5/6.4 下安裝PostgreSQL 9.3 與 phpPgAdmin
------------------------------------華麗麗的分割線------------------------------------
PostgreSQL 的詳細介紹:請點這裡
PostgreSQL 的:請點這裡
本文永久更新連結地址: