可以使用help
语句查看所有postgresql语句的语法。 按照以下步骤查看postgresql中所有语句的语法。
psql
为:程序文件 -> postgresql 9.2 -> sql shell(psql)在这里,我们提供了所有postgresql语句及其语法的列表:
abort语句:
语法:
abort [ work | transaction ]
alter aggregate语句:
语法:
alter aggregate name ( type ) rename to new_name
alter aggregate name ( type ) owner to new_owner
alter conversion语句:
语法:
alter conversion name rename to new_name
alter conversion name owner to new_owner
alter database语句:
语法:
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
alter domain语句:
语法:
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
alter function语句:
语法:
alter function name ( [ type [, ...] ] ) rename to new_name
alter function name ( [ type [, ...] ] ) owner to new_owner
alter group语句:
语法:
alter group groupname add user username [, ... ]
alter group groupname drop user username [, ... ]
alter group groupname rename to new_name
alter index语句:
语法:
alter index name owner to new_owner
alter index name set tablespace indexspace_name
alter index name rename to new_name
alter language语句:
语法:
alter language name rename to new_name
alter operator语句:
语法:
alter operator name ( { lefttype | none } , { righttype | none } )
owner to new_owner
alter operator class语句:
语法:
alter operator class name using index_method rename to new_name
alter operator class name using index_method owner to new_owner
alter schema语句:
语法:
alter schema name rename to new_name
alter schema name owner to new_owner
alter sequence语句:
语法:
alter sequence name [ increment [ by ] increment ]
[ minvalue minvalue | no minvalue ]
[ maxvalue maxvalue | no maxvalue ]
[ restart [ with ] start ] [ cache cache ] [ [ no ] cycle ]
alter table语句:
语法:
alter table [ only ] name [ * ]
action [, ... ]
alter table [ only ] name [ * ]
rename [ column ] column to new_column
alter table name
rename to new_name
alter tablespace语句:
语法:
alter tablespace name rename to new_name
alter tablespace name owner to new_owner
alter trigger语句:
语法:
alter trigger name on table rename to new_name
alter type语句:
语法:
alter type name owner to new_owner
alter user语句:
语法:
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
analyse语句:
语法:
analyze [ verbose ] [ table [ (column [, ...] ) ] ]
begin语句:
语法:
begin [ work | transaction ] [ transaction_mode [, ...] ]
checkpoint语句:
语法:
checkpoint
close语句:
语法:
close name
cluster语句:
语法:
cluster index_name on table_name
cluster table_name
cluster
commit语句:
语法:
commit [ work | transaction ]
copy语句:
语法:
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 [, ...] ]
create aggregate语句:
语法:
create aggregate name (
basetype = input_data_type,
sfunc = sfunc,
stype = state_data_type
[ , finalfunc = ffunc ]
[ , initcond = initial_condition ]
)
create cast语句:
语法:
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 ]
create constraint trigger语句:
语法:
create constraint trigger name
after events on
table_name constraint attributes
for each row execute procedure func_name ( args )
create conversion语句:
语法:
create [default] conversion name
for source_encoding to dest_encoding from func_name
create database语句:
语法:
create database name
[ [ with ] [ owner [=] db_owner ]
[ template [=] template ]
[ encoding [=] encoding ]
[ tablespace [=] tablespace ] ]
create domain语句:
语法:
create domain name [as] data_type
[ default expression ]
[ constraint [ ... ] ]
create function语句:
语法:
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 [, ...] ) ]
create group语句:
语法:
create group name [ [ with ] option [ ... ] ]
where option can be:
sysid gid
| user username [, ...]
create index语句:
语法:
create [ unique ] index name on table [ using method ]
( { column | ( expression ) } [ opclass ] [, ...] )
[ tablespace tablespace ]
[ where predicate ]
create language语句:
语法:
create [ trusted ] [ procedural ] language name
handler call_handler [ validator val_function ]
create operator语句:
语法:
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 ]
)
create operator class语句:
语法:
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
} [, ... ]
create rule语句:
语法:
create [ or replace ] rule name as on event
to table [ where condition ]
do [ also | instead ] { nothing | command | ( command ; command ... ) }
create schema语句:
语法:
create schema schema_name
[ authorization username ] [ schema_element [ ... ] ]
create schema authorization username
[ schema_element [ ... ] ]
create sequence语句:
语法:
create [ temporary | temp ] sequence name
[ increment [ by ] increment ]
[ minvalue minvalue | no minvalue ]
[ maxvalue maxvalue | no maxvalue ]
[ start [ with ] start ] [ cache cache ] [ [ no ] cycle ]
create table语句:
语法:
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 ]
create table as语句:
语法:
create [ [ global | local ] { temporary | temp } ] table table_name
[ (column_name [, ...] ) ] [ [ with | without ] oids ]
as query
create tablespace语句:
语法:
create tablespace tablespace_name [ owner username ] location 'directory'
crfeate trigger语句:
语法:
create trigger name { before | after } { event [ or ... ] }
on table [ for [ each ] { row | statement } ]
execute procedure func_name ( arguments )
create type语句:
语法:
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 ]
)
create user语句:
语法:
create user name [ [ with ] option [ ... ] ]
create view语句:
语法:
create [ or replace ] view name [ ( column_name [, ...] ) ] as query
deallocate语句:
语法:
deallocate [ prepare ] plan_name
declare语句:
语法:
declare name [ binary ] [ insensitive ] [ [ no ] scroll ]
cursor [ { with | without } hold ] for query
[ for { read only | update [ of column [, ...] ] } ]
delete语句:
语法:
delete from [ only ] table [ where condition ]
drop aggregate语句:
语法:
drop aggregate name ( type ) [ cascade | restrict ]
drop cast语句:
语法:
drop cast (source_type as target_type) [ cascade | restrict ]
drop conversion语句:
语法:
drop conversion name [ cascade | restrict ]
drop database语句:
语法:
drop database name
drop domain语句:
语法:
drop domain name [, ...] [ cascade | restrict ]
drop function语句:
语法:
drop function name ( [ type [, ...] ] ) [ cascade | restrict ]
drop group语句:
语法:
drop group name
drop index语句:
语法:
drop index name [, ...] [ cascade | restrict ]
drop language语句:
语法:
drop [ procedural ] language name [ cascade | restrict ]
drop operator语句:
语法:
drop operator name ( { left_type | none } , { right_type | none } )
[ cascade | restrict ]
drop operator class语句:
语法:
drop operator class name using index_method [ cascade | restrict ]
drop rule语句:
语法:
drop rule name on relation [cascade | restrict ]
drop schema语句:
语法:
drop schema name [, ...] [ cascade | restrict ]
drop sequence语句:
语法:
drop sequence name [, ...] [ cascade | restrict ]
drop table语句:
语法:
drop table name [, ...] [ cascade | restrict ]
drop tablespace语句:
语法:
drop tablespace tablespace_name
drop trigger语句:
语法:
drop trigger name on table [ cascade | restrict ]
drop type语句:
语法:
drop type name [, ...] [ cascade | restrict ]
drop user语句:
语法:
drop user name
drop view语句:
语法:
drop view name [, ...] [ cascade | restrict ]
end语句:
语法:
end [ work | transaction ]
execute语句:
语法:
execute plan_name [ (parameter [, ...] ) ]
explain语句:
语法:
explain [ analyze ] [ verbose ] statement
fetch语句:
语法:
fetch [ direction { from | in } ] cursor_name
insert语句:
语法:
insert into table [ ( column [, ...] ) ]
{ default values | values ( { expression | default } [, ...] ) | query }
listen语句:
语法:
listen name
load语句:
语法:
load 'filename'
lock语句:
语法:
lock [ table ] name [, ...] [ in lock_mode mode ] [ nowait ]
move语句:
语法:
move [ direction { from | in } ] cursor_name
notify语句:
语法:
notify name
prepare语句:
语法:
prepare plan_name [ (data_type [, ...] ) ] as statement
reindex语句:
语法:
reindex { database | table | index } name [ force ]
reset语句:
语法:
reset name
reset all
rollback语句:
语法:
rollback [ work | transaction ]
rollback to savepoint语句:
语法:
rollback [ work | transaction ] to [ savepoint ] savepoint_name
savepoint语句:
语法:
savepoint savepoint_name
select语句:
语法:
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 [, ...] ] ]
select into语句:
语法:
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 [, ...] ] ]
set语句:
语法:
set [ session | local ] name { to | = } { value | 'value' | default }
set [ session | local ] time zone { time_zone | local | default }
set constraints语句:
语法:
set constraints { all | name [, ...] } { deferred | immediate }
set transaction语句:
语法:
set transaction transaction_mode [, ...]
set session characteristics as transaction transaction_mode [, ...]
show语句:
语法:
show name
show all
start transaction语句:
语法:
start transaction [ transaction_mode [, ...] ]
truncate table语句:
语法:
truncate [ table ] name
update语句:
语法:
update [ only ] table set column = { expression | default } [, ...]
[ from from_list ]
[ where condition ]