默認(rèn)情況下 PostgreSQL 安裝完成后,自帶了一個(gè)命令行工具 SQL Shell(psql)。
Linux 系統(tǒng)可以直接切換到 postgres 用戶來(lái)開啟命令行工具:
# sudo -i -u postgres
Windows 系統(tǒng)一般在它的安裝目錄下:
Program Files → PostgreSQL 11.3 → SQL Shell(psql)
Mac OS 我們直接搜索就可以了找到:
進(jìn)入命令行工具,我們可以使用 \help 來(lái)查看各個(gè)命令的語(yǔ)法 :
postgres-# \help <command_name>
例如,我們查看下 select 語(yǔ)句的語(yǔ)法:
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 可以是以下選項(xiàng)之一: [ ONLY ] table_name [ * ] [ [ AS ] alias [ ( column_alias [, ...] ) ] ]
一個(gè) SQL 語(yǔ)句通常包含了關(guān)鍵字、標(biāo)識(shí)符(字段)、常量、特殊符號(hào)等,下面是一個(gè)簡(jiǎn)單的 SQL 語(yǔ)句:
SELECT id, name FROM w3cschool
SELECT | id, name | FROM | w3cschool
|
|
---|---|---|---|---|
符號(hào)類型 | 關(guān)鍵字 | 標(biāo)識(shí)符(字段) | 關(guān)鍵字 | 標(biāo)識(shí)符 |
描述 | 命令 | id 和 name 字段 | 語(yǔ)句,用于設(shè)置條件規(guī)則等 | 表名 |
ABORT 用于退出當(dāng)前事務(wù)。
ABORT [ WORK | TRANSACTION ]
修改一個(gè)聚集函數(shù)的定義 。
ALTER AGGREGATE _name_ ( _argtype_ [ , ... ] ) RENAME TO _new_name_ ALTER AGGREGATE _name_ ( _argtype_ [ , ... ] ) OWNER TO _new_owner_ ALTER AGGREGATE _name_ ( _argtype_ [ , ... ] ) SET SCHEMA _new_schema_
修改一個(gè)排序規(guī)則定義 。
ALTER COLLATION _name_ RENAME TO _new_name_ ALTER COLLATION _name_ OWNER TO _new_owner_ ALTER COLLATION _name_ SET SCHEMA _new_schema_
修改一個(gè)編碼轉(zhuǎn)換的定義。
ALTER CONVERSION name RENAME TO new_name ALTER CONVERSION name OWNER TO new_owner
修改一個(gè)數(shù)據(jù)庫(kù)。
ALTER DATABASE name SET parameter { TO | = } { value | DEFAULT } ALTER DATABASE name RESET parameter ALTER DATABASE name RENAME TO new_name ALTER DATABASE name OWNER TO new_owner
定義默認(rèn)的訪問(wèn)權(quán)限。
ALTER DEFAULT PRIVILEGES [ FOR { ROLE | USER } target_role [, ...] ] [ IN SCHEMA schema_name [, ...] ] abbreviated_grant_or_revoke where abbreviated_grant_or_revoke is one of: GRANT { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER } [, ...] | ALL [ PRIVILEGES ] } ON TABLES TO { [ GROUP ] role_name | PUBLIC } [, ...] [ WITH GRANT OPTION ] ...
修改一個(gè)域的定義。
ALTER DOMAIN name { SET DEFAULT expression | DROP DEFAULT } ALTER DOMAIN name { SET | DROP } NOT NULL ALTER DOMAIN name ADD domain_constraint ALTER DOMAIN name DROP CONSTRAINT constraint_name [ RESTRICT | CASCADE ] ALTER DOMAIN name OWNER TO new_owner
修改一個(gè)函數(shù)的定義。
ALTER FUNCTION name ( [ type [, ...] ] ) RENAME TO new_name ALTER FUNCTION name ( [ type [, ...] ] ) OWNER TO new_owner
修改一個(gè)用戶組。
ALTER GROUP groupname ADD USER username [, ... ] ALTER GROUP groupname DROP USER username [, ... ] ALTER GROUP groupname RENAME TO new_name
修改一個(gè)索引的定義。
ALTER INDEX name OWNER TO new_owner ALTER INDEX name SET TABLESPACE indexspace_name ALTER INDEX name RENAME TO new_name
修改一個(gè)過(guò)程語(yǔ)言的定義。
ALTER LANGUAGE name RENAME TO new_name
改變一個(gè)操作符的定義。
ALTER OPERATOR name ( { lefttype | NONE }, { righttype | NONE } ) OWNER TO new_owner
修改一個(gè)操作符表的定義。
ALTER OPERATOR CLASS name USING index_method RENAME TO new_name ALTER OPERATOR CLASS name USING index_method OWNER TO new_owner
修改一個(gè)模式的定義。
ALTER SCHEMA name RENAME TO new_name ALTER SCHEMA name OWNER TO new_owner
修改一個(gè)序列生成器的定義。
ALTER SEQUENCE name [ INCREMENT [ BY ] increment ] [ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ] [ RESTART [ WITH ] start ] [ CACHE cache ] [ [ NO ] CYCLE ]
修改表的定義。
ALTER TABLE [ ONLY ] name [ * ] action [, ... ] ALTER TABLE [ ONLY ] name [ * ] RENAME [ COLUMN ] column TO new_column ALTER TABLE name RENAME TO new_name
其中 action 可以是以選項(xiàng)之一:
ADD [ COLUMN ] column_type [ column_constraint [ ... ] ] DROP [ COLUMN ] column [ RESTRICT | CASCADE ] ALTER [ COLUMN ] column TYPE type [ USING expression ] ALTER [ COLUMN ] column SET DEFAULT expression ALTER [ COLUMN ] column DROP DEFAULT ALTER [ COLUMN ] column { SET | DROP } NOT NULL ALTER [ COLUMN ] column SET STATISTICS integer ALTER [ COLUMN ] column SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN } ADD table_constraint DROP CONSTRAINT constraint_name [ RESTRICT | CASCADE ] CLUSTER ON index_name SET WITHOUT CLUSTER SET WITHOUT OIDS OWNER TO new_owner SET TABLESPACE tablespace_name
修改一個(gè)表空間的定義。
ALTER TABLESPACE name RENAME TO new_name ALTER TABLESPACE name OWNER TO new_owner
修改改變一個(gè)觸發(fā)器的定義 。
ALTER TRIGGER name ON table RENAME TO new_name
修改一個(gè)類型的定義 。
ALTER TYPE name OWNER TO new_owner
修改數(shù)據(jù)庫(kù)用戶帳號(hào) 。
ALTER USER name [ [ WITH ] option [ ... ] ] ALTER USER name RENAME TO new_name ALTER USER name SET parameter { TO | = } { value | DEFAULT } ALTER USER name RESET parameter
Where option can be ?
[ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password' | CREATEDB | NOCREATEDB | CREATEUSER | NOCREATEUSER | VALID UNTIL 'abstime'
收集與數(shù)據(jù)庫(kù)有關(guān)的統(tǒng)計(jì)。
ANALYZE [ VERBOSE ] [ table [ (column [, ...] ) ] ]
開始一個(gè)事務(wù)塊。
BEGIN [ WORK | TRANSACTION ] [ transaction_mode [, ...] ]
transaction_mode 可以是以下選項(xiàng)之一:
ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED } READ WRITE | READ ONLY
強(qiáng)制一個(gè)事務(wù)日志檢查點(diǎn) 。
CHECKPOINT
關(guān)閉游標(biāo)。
CLOSE name
根據(jù)一個(gè)索引對(duì)某個(gè)表盤簇化排序。
CLUSTER index_name ON table_name CLUSTER table_name CLUSTER
定義或者改變一個(gè)對(duì)象的注釋。
COMMENT ON { TABLE object_name | COLUMN table_name.column_name | AGGREGATE agg_name (agg_type) | CAST (source_type AS target_type) | CONSTRAINT constraint_name ON table_name | CONVERSION object_name | DATABASE object_name | DOMAIN object_name | FUNCTION func_name (arg1_type, arg2_type, ...) | INDEX object_name | LARGE OBJECT large_object_oid | OPERATOR op (left_operand_type, right_operand_type) | OPERATOR CLASS object_name USING index_method | [ PROCEDURAL ] LANGUAGE object_name | RULE rule_name ON table_name | SCHEMA object_name | SEQUENCE object_name | TRIGGER trigger_name ON table_name | TYPE object_name | VIEW object_name } IS 'text'
提交當(dāng)前事務(wù)。
COMMIT [ WORK | TRANSACTION ]
在表和文件之間拷貝數(shù)據(jù)。
COPY table_name [ ( column [, ...] ) ] FROM { 'filename' | STDIN } [ WITH ] [ BINARY ] [ OIDS ] [ DELIMITER [ AS ] 'delimiter' ] [ NULL [ AS ] 'null string' ] [ CSV [ QUOTE [ AS ] 'quote' ] [ ESCAPE [ AS ] 'escape' ] [ FORCE NOT NULL column [, ...] ] COPY table_name [ ( column [, ...] ) ] TO { 'filename' | STDOUT } [ [ WITH ] [ BINARY ] [ OIDS ] [ DELIMITER [ AS ] 'delimiter' ] [ NULL [ AS ] 'null string' ] [ CSV [ QUOTE [ AS ] 'quote' ] [ ESCAPE [ AS ] 'escape' ] [ FORCE QUOTE column [, ...] ]
定義一個(gè)新的聚集函數(shù)。
CREATE AGGREGATE name ( BASETYPE = input_data_type, SFUNC = sfunc, STYPE = state_data_type [, FINALFUNC = ffunc ] [, INITCOND = initial_condition ] )
定義一個(gè)用戶定義的轉(zhuǎn)換。
CREATE CAST (source_type AS target_type) WITH FUNCTION func_name (arg_types) [ AS ASSIGNMENT | AS IMPLICIT ] CREATE CAST (source_type AS target_type) WITHOUT FUNCTION [ AS ASSIGNMENT | AS IMPLICIT ]
定義一個(gè)新的約束觸發(fā)器 。
CREATE CONSTRAINT TRIGGER name AFTER events ON table_name constraint attributes FOR EACH ROW EXECUTE PROCEDURE func_name ( args )
定義一個(gè)新的的編碼轉(zhuǎn)換。
CREATE [DEFAULT] CONVERSION name FOR source_encoding TO dest_encoding FROM func_name
創(chuàng)建新數(shù)據(jù)庫(kù)。
CREATE DATABASE name [ [ WITH ] [ OWNER [=] db_owner ] [ TEMPLATE [=] template ] [ ENCODING [=] encoding ] [ TABLESPACE [=] tablespace ] ]
定義一個(gè)新域。
CREATE DOMAIN name [AS] data_type [ DEFAULT expression ] [ constraint [ ... ] ]
constraint 可以是以下選項(xiàng)之一:
[ CONSTRAINT constraint_name ] { NOT NULL | NULL | CHECK (expression) }
定義一個(gè)新函數(shù)。
CREATE [ OR REPLACE ] FUNCTION name ( [ [ arg_name ] arg_type [, ...] ] ) RETURNS ret_type { LANGUAGE lang_name | IMMUTABLE | STABLE | VOLATILE | CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT | [ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER | AS 'definition' | AS 'obj_file', 'link_symbol' } ... [ WITH ( attribute [, ...] ) ]
定義一個(gè)新的用戶組。
CREATE GROUP name [ [ WITH ] option [ ... ] ] Where option can be: SYSID gid | USER username [, ...]
定義一個(gè)新索引。
CREATE [ UNIQUE ] INDEX name ON table [ USING method ] ( { column | ( expression ) } [ opclass ] [, ...] ) [ TABLESPACE tablespace ] [ WHERE predicate ]
定義一種新的過(guò)程語(yǔ)言。
CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE name HANDLER call_handler [ VALIDATOR val_function ]
定義一個(gè)新的操作符。
CREATE OPERATOR name ( PROCEDURE = func_name [, LEFTARG = left_type ] [, RIGHTARG = right_type ] [, COMMUTATOR = com_op ] [, NEGATOR = neg_op ] [, RESTRICT = res_proc ] [, JOIN = join_proc ] [, HASHES ] [, MERGES ] [, SORT1 = left_sort_op ] [, SORT2 = right_sort_op ] [, LTCMP = less_than_op ] [, GTCMP = greater_than_op ] )
定義一個(gè)新的操作符表。
CREATE OPERATOR CLASS name [ DEFAULT ] FOR TYPE data_type USING index_method AS { OPERATOR strategy_number operator_name [ ( op_type, op_type ) ] [ RECHECK ] | FUNCTION support_number func_name ( argument_type [, ...] ) | STORAGE storage_type } [, ... ]
定義一個(gè)新的數(shù)據(jù)庫(kù)角色。
CREATE ROLE _name_ [ [ WITH ] _option_ [ ... ] ] where `_option_` can be: SUPERUSER | NOSUPERUSER | CREATEDB | NOCREATEDB | CREATEROLE | NOCREATEROLE ...
定義一個(gè)新重寫規(guī)則。
CREATE [ OR REPLACE ] RULE name AS ON event TO table [ WHERE condition ] DO [ ALSO | INSTEAD ] { NOTHING | command | ( command ; command ... ) }
定義一個(gè)新模式。
CREATE SCHEMA schema_name [ AUTHORIZATION username ] [ schema_element [ ... ] ] CREATE SCHEMA AUTHORIZATION username [ schema_element [ ... ] ]
定義一個(gè)新的外部服務(wù)器。。
CREATE SERVER _server_name_ [ TYPE '_server_type_' ] [ VERSION '_server_version_' ] FOREIGN DATA WRAPPER _fdw_name_ [ OPTIONS ( _option_ '_value_' [, ... ] ) ]
定義一個(gè)新序列發(fā)生器。
CREATE [ TEMPORARY | TEMP ] SEQUENCE name [ INCREMENT [ BY ] increment ] [ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ] [ START [ WITH ] start ] [ CACHE cache ] [ [ NO ] CYCLE ]
定義一個(gè)新表。
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name ( { column_name data_type [ DEFAULT default_expr ] [ column_constraint [ ... ] ] | table_constraint | LIKE parent_table [ { INCLUDING | EXCLUDING } DEFAULTS ] } [, ... ] ) [ INHERITS ( parent_table [, ... ] ) ] [ WITH OIDS | WITHOUT OIDS ] [ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ] [ TABLESPACE tablespace ]
column_constraint 可以是以下選項(xiàng)之一:
[ CONSTRAINT constraint_name ] { NOT NULL | NULL | UNIQUE [ USING INDEX TABLESPACE tablespace ] | PRIMARY KEY [ USING INDEX TABLESPACE tablespace ] | CHECK (expression) | REFERENCES ref_table [ ( ref_column ) ] [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ] [ ON DELETE action ] [ ON UPDATE action ] } [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
table_constraint 可以是以下選項(xiàng)之一:
[ CONSTRAINT constraint_name ] { UNIQUE ( column_name [, ... ] ) [ USING INDEX TABLESPACE tablespace ] | PRIMARY KEY ( column_name [, ... ] ) [ USING INDEX TABLESPACE tablespace ] | CHECK ( expression ) | FOREIGN KEY ( column_name [, ... ] ) REFERENCES ref_table [ ( ref_column [, ... ] ) ] [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ] [ ON DELETE action ] [ ON UPDATE action ] } [ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
從一條查詢的結(jié)果中定義一個(gè)新表。
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name [ (column_name [, ...] ) ] [ [ WITH | WITHOUT ] OIDS ] AS query
定義一個(gè)新的表空間。
CREATE TABLESPACE tablespace_name [ OWNER username ] LOCATION 'directory'
定義一個(gè)新的觸發(fā)器。
CREATE TRIGGER name { BEFORE | AFTER } { event [ OR ... ] } ON table [ FOR [ EACH ] { ROW | STATEMENT } ] EXECUTE PROCEDURE func_name ( arguments )
定義一個(gè)新的數(shù)據(jù)類型。
CREATE TYPE name AS ( attribute_name data_type [, ... ] ) CREATE TYPE name ( INPUT = input_function, OUTPUT = output_function [, RECEIVE = receive_function ] [, SEND = send_function ] [, ANALYZE = analyze_function ] [, INTERNALLENGTH = { internal_length | VARIABLE } ] [, PASSEDBYVALUE ] [, ALIGNMENT = alignment ] [, STORAGE = storage ] [, DEFAULT = default ] [, ELEMENT = element ] [, DELIMITER = delimiter ] )
創(chuàng)建一個(gè)新的數(shù)據(jù)庫(kù)用戶帳戶。
CREATE USER name [ [ WITH ] option [ ... ] ]
option 可以是以下選項(xiàng)之一:
SYSID uid | [ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password' | CREATEDB | NOCREATEDB | CREATEUSER | NOCREATEUSER | IN GROUP group_name [, ...] | VALID UNTIL 'abs_time'
定義一個(gè)視圖。
CREATE [ OR REPLACE ] VIEW name [ ( column_name [, ...] ) ] AS query
刪除一個(gè)準(zhǔn)備好的查詢。
DEALLOCATE [ PREPARE ] plan_name
定義一個(gè)游標(biāo)。
DECLARE name [ BINARY ] [ INSENSITIVE ] [ [ NO ] SCROLL ] CURSOR [ { WITH | WITHOUT } HOLD ] FOR query [ FOR { READ ONLY | UPDATE [ OF column [, ...] ] } ]
刪除一個(gè)表中的行。
DELETE FROM [ ONLY ] table [ WHERE condition ]
刪除一個(gè)用戶定義的聚集函數(shù)。
DROP AGGREGATE name ( type ) [ CASCADE | RESTRICT ]
刪除一個(gè)用戶定義的類型轉(zhuǎn)換。
DROP CAST (source_type AS target_type) [ CASCADE | RESTRICT ]
刪除一個(gè)用戶定義的編碼轉(zhuǎn)換。
DROP CONVERSION name [ CASCADE | RESTRICT ]
刪除一個(gè)數(shù)據(jù)庫(kù)。
DROP DATABASE name
刪除一個(gè)用戶定義的域。
DROP DOMAIN name [, ...] [ CASCADE | RESTRICT ]
刪除一個(gè)函數(shù)。
DROP FUNCTION name ( [ type [, ...] ] ) [ CASCADE | RESTRICT ]
刪除一個(gè)用戶組。
DROP GROUP name
刪除一個(gè)索引。
DROP INDEX name [, ...] [ CASCADE | RESTRICT ]
刪除一個(gè)過(guò)程語(yǔ)言。
DROP [ PROCEDURAL ] LANGUAGE name [ CASCADE | RESTRICT ]
刪除一個(gè)操作符。
DROP OPERATOR name ( { left_type | NONE }, { right_type | NONE } ) [ CASCADE | RESTRICT ]
刪除一個(gè)操作符表。
DROP OPERATOR CLASS name USING index_method [ CASCADE | RESTRICT ]
刪除一個(gè)數(shù)據(jù)庫(kù)角色。
DROP ROLE [ IF EXISTS ] _name_ [, ...]
刪除一個(gè)重寫規(guī)則。
DROP RULE name ON relation [ CASCADE | RESTRICT ]
刪除一個(gè)模式。
DROP SCHEMA name [, ...] [ CASCADE | RESTRICT ]
刪除一個(gè)序列。
DROP SEQUENCE name [, ...] [ CASCADE | RESTRICT ]
刪除一個(gè)表。
DROP TABLE name [, ...] [ CASCADE | RESTRICT ]
刪除一個(gè)表空間。
DROP TABLESPACE tablespace_name
刪除一個(gè)觸發(fā)器定義。
DROP TRIGGER name ON table [ CASCADE | RESTRICT ]
刪除一個(gè)用戶定義數(shù)據(jù)類型。
DROP TYPE name [, ...] [ CASCADE | RESTRICT ]
刪除一個(gè)數(shù)據(jù)庫(kù)用戶帳號(hào)。
DROP USER name
刪除一個(gè)視圖。
DROP VIEW name [, ...] [ CASCADE | RESTRICT ]
提交當(dāng)前的事務(wù)。
END [ WORK | TRANSACTION ]
執(zhí)行一個(gè)準(zhǔn)備好的查詢。
EXECUTE plan_name [ (parameter [, ...] ) ]
顯示一個(gè)語(yǔ)句的執(zhí)行規(guī)劃。
EXPLAIN [ ANALYZE ] [ VERBOSE ] statement
用游標(biāo)從查詢中抓取行。
FETCH [ direction { FROM | IN } ] cursor_name
direction 可以是以下選項(xiàng)之一:
NEXT PRIOR FIRST LAST ABSOLUTE count RELATIVE count count ALL FORWARD FORWARD count FORWARD ALL BACKWARD BACKWARD count BACKWARD ALL
定義訪問(wèn)權(quán)限。
GRANT { { SELECT | INSERT | UPDATE | DELETE | RULE | REFERENCES | TRIGGER } [,...] | ALL [ PRIVILEGES ] } ON [ TABLE ] table_name [, ...] TO { username | GROUP group_name | PUBLIC } [, ...] [ WITH GRANT OPTION ] GRANT { { CREATE | TEMPORARY | TEMP } [,...] | ALL [ PRIVILEGES ] } ON DATABASE db_name [, ...] TO { username | GROUP group_name | PUBLIC } [, ...] [ WITH GRANT OPTION ] GRANT { CREATE | ALL [ PRIVILEGES ] } ON TABLESPACE tablespace_name [, ...] TO { username | GROUP group_name | PUBLIC } [, ...] [ WITH GRANT OPTION ] GRANT { EXECUTE | ALL [ PRIVILEGES ] } ON FUNCTION func_name ([type, ...]) [, ...] TO { username | GROUP group_name | PUBLIC } [, ...] [ WITH GRANT OPTION ] GRANT { USAGE | ALL [ PRIVILEGES ] } ON LANGUAGE lang_name [, ...] TO { username | GROUP group_name | PUBLIC } [, ...] [ WITH GRANT OPTION ] GRANT { { CREATE | USAGE } [,...] | ALL [ PRIVILEGES ] } ON SCHEMA schema_name [, ...] TO { username | GROUP group_name | PUBLIC } [, ...] [ WITH GRANT OPTION ]
在表中創(chuàng)建新行,即插入數(shù)據(jù)。
INSERT INTO table [ ( column [, ...] ) ] { DEFAULT VALUES | VALUES ( { expression | DEFAULT } [, ...] ) | query }
監(jiān)聽一個(gè)通知。
LISTEN name
加載或重載一個(gè)共享庫(kù)文件。
LOAD 'filename'
鎖定一個(gè)表。
LOCK [ TABLE ] name [, ...] [ IN lock_mode MODE ] [ NOWAIT ]
lock_mode 可以是以下選項(xiàng)之一:
ACCESS SHARE | ROW SHARE | ROW EXCLUSIVE | SHARE UPDATE EXCLUSIVE | SHARE | SHARE ROW EXCLUSIVE | EXCLUSIVE | ACCESS EXCLUSIVE
定位一個(gè)游標(biāo)。
MOVE [ direction { FROM | IN } ] cursor_name
生成一個(gè)通知。
NOTIFY name
創(chuàng)建一個(gè)準(zhǔn)備好的查詢。
PREPARE plan_name [ (data_type [, ...] ) ] AS statement
重建索引。
REINDEX { DATABASE | TABLE | INDEX } name [ FORCE ]
刪除一個(gè)前面定義的保存點(diǎn)。
RELEASE [ SAVEPOINT ] savepoint_name
把一個(gè)運(yùn)行時(shí)參數(shù)值恢復(fù)為默認(rèn)值。
RESET name RESET ALL
刪除訪問(wèn)權(quán)限。
REVOKE [ GRANT OPTION FOR ] { { SELECT | INSERT | UPDATE | DELETE | RULE | REFERENCES | TRIGGER } [,...] | ALL [ PRIVILEGES ] } ON [ TABLE ] table_name [, ...] FROM { username | GROUP group_name | PUBLIC } [, ...] [ CASCADE | RESTRICT ] REVOKE [ GRANT OPTION FOR ] { { CREATE | TEMPORARY | TEMP } [,...] | ALL [ PRIVILEGES ] } ON DATABASE db_name [, ...] FROM { username | GROUP group_name | PUBLIC } [, ...] [ CASCADE | RESTRICT ] REVOKE [ GRANT OPTION FOR ] { CREATE | ALL [ PRIVILEGES ] } ON TABLESPACE tablespace_name [, ...] FROM { username | GROUP group_name | PUBLIC } [, ...] [ CASCADE | RESTRICT ] REVOKE [ GRANT OPTION FOR ] { EXECUTE | ALL [ PRIVILEGES ] } ON FUNCTION func_name ([type, ...]) [, ...] FROM { username | GROUP group_name | PUBLIC } [, ...] [ CASCADE | RESTRICT ] REVOKE [ GRANT OPTION FOR ] { USAGE | ALL [ PRIVILEGES ] } ON LANGUAGE lang_name [, ...] FROM { username | GROUP group_name | PUBLIC } [, ...] [ CASCADE | RESTRICT ] REVOKE [ GRANT OPTION FOR ] { { CREATE | USAGE } [,...] | ALL [ PRIVILEGES ] } ON SCHEMA schema_name [, ...] FROM { username | GROUP group_name | PUBLIC } [, ...] [ CASCADE | RESTRICT ]
退出當(dāng)前事務(wù)。
ROLLBACK [ WORK | TRANSACTION ]
回滾到一個(gè)保存點(diǎn)。
ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] savepoint_name
在當(dāng)前事務(wù)里定義一個(gè)新的保存點(diǎn)。
SAVEPOINT savepoint_name
從表或視圖中取出若干行。
SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ] * | expression [ AS output_name ] [, ...] [ FROM from_item [, ...] ] [ WHERE condition ] [ GROUP BY expression [, ...] ] [ HAVING condition [, ...] ] [ { UNION | INTERSECT | EXCEPT } [ ALL ] select ] [ ORDER BY expression [ ASC | DESC | USING operator ] [, ...] ] [ LIMIT { count | ALL } ] [ OFFSET start ] [ FOR UPDATE [ OF table_name [, ...] ] ]
from_item 可以是以下選項(xiàng):
[ ONLY ] table_name [ * ] [ [ AS ] alias [ ( column_alias [, ...] ) ] ] ( select ) [ AS ] alias [ ( column_alias [, ...] ) ] function_name ( [ argument [, ...] ] ) [ AS ] alias [ ( column_alias [, ...] | column_definition [, ...] ) ] function_name ( [ argument [, ...] ] ) AS ( column_definition [, ...] ) from_item [ NATURAL ] join_type from_item [ ON join_condition | USING ( join_column [, ...] ) ]
從一個(gè)查詢的結(jié)果中定義一個(gè)新表。
SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ] * | expression [ AS output_name ] [, ...] INTO [ TEMPORARY | TEMP ] [ TABLE ] new_table [ FROM from_item [, ...] ] [ WHERE condition ] [ GROUP BY expression [, ...] ] [ HAVING condition [, ...] ] [ { UNION | INTERSECT | EXCEPT } [ ALL ] select ] [ ORDER BY expression [ ASC | DESC | USING operator ] [, ...] ] [ LIMIT { count | ALL } ] [ OFFSET start ] [ FOR UPDATE [ OF table_name [, ...] ] ]
修改運(yùn)行時(shí)參數(shù)。
SET [ SESSION | LOCAL ] name { TO | = } { value | 'value' | DEFAULT } SET [ SESSION | LOCAL ] TIME ZONE { time_zone | LOCAL | DEFAULT }
設(shè)置當(dāng)前事務(wù)的約束檢查模式。
SET CONSTRAINTS { ALL | name [, ...] } { DEFERRED | IMMEDIATE }
為當(dāng)前會(huì)話設(shè)置會(huì)話用戶標(biāo)識(shí)符和當(dāng)前用戶標(biāo)識(shí)符。
SET [ SESSION | LOCAL ] SESSION AUTHORIZATION username SET [ SESSION | LOCAL ] SESSION AUTHORIZATION DEFAULT RESET SESSION AUTHORIZATION
開始一個(gè)事務(wù)塊。
SET TRANSACTION transaction_mode [, ...] SET SESSION CHARACTERISTICS AS TRANSACTION transaction_mode [, ...]
Where transaction_mode is one of ?
ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED } READ WRITE | READ ONLY
顯示運(yùn)行時(shí)參數(shù)的值。
SHOW name SHOW ALL
開始一個(gè)事務(wù)塊。
START TRANSACTION [ transaction_mode [, ...] ]
transaction_mode 可以是下面的選項(xiàng)之一:
ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED } READ WRITE | READ ONLY
清空一個(gè)或一組表。
TRUNCATE [ TABLE ] name
停止監(jiān)聽通知信息。
UNLISTEN { name | * }
更新一個(gè)表中的行。
UPDATE [ ONLY ] table SET column = { expression | DEFAULT } [, ...] [ FROM from_list ] [ WHERE condition ]
垃圾收集以及可選地分析一個(gè)數(shù)據(jù)庫(kù)。
VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ table ] VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] ANALYZE [ table [ (column [, ...] ) ] ]
計(jì)算一個(gè)或一組行。
VALUES ( _expression_ [, ...] ) [, ...] [ ORDER BY _sort_expression_ [ ASC | DESC | USING _operator_ ] [, ...] ] [ LIMIT { _count_ | ALL } ] [ OFFSET _start_ [ ROW | ROWS ] ] [ FETCH { FIRST | NEXT } [ _count_ ] { ROW | ROWS } ONLY ]
更多建議: