abort

abort ::= ABORT [ TRANSACTION | WORK ]

ABORTTRANSACTIONWORK

alter_database

alter_database ::= ALTER DATABASE name
                   [ [ WITH ] alter_database_option [ ... ]
                     | RENAME TO name
                     | OWNER TO { new_owner
                                  | CURRENT_USER
                                  | SESSION_USER }
                     | SET configuration_parameter { TO | = }
                       { value | DEFAULT }
                     | SET configuration_parameter FROM CURRENT
                     | RESET configuration_parameter
                     | RESET ALL ]

ALTERDATABASEnameWITHalter_database_optionRENAMETOnameOWNERTOnew_ownerCURRENT_USERSESSION_USERSETconfiguration_parameterTO=valueDEFAULTSETconfiguration_parameterFROMCURRENTRESETconfiguration_parameterRESETALL

alter_database_option

alter_database_option ::= ALLOW_CONNECTIONS allowconn
                          | CONNECTION LIMIT connlimit
                          | IS_TEMPLATE istemplate

ALLOW_CONNECTIONSallowconnCONNECTIONLIMITconnlimitIS_TEMPLATEistemplate

alter_default_priv

alter_default_priv ::= ALTER DEFAULT PRIVILEGES
                       [ FOR { ROLE | USER } role_name [ , ... ] ]
                       [ IN SCHEMA schema_name [ , ... ] ]
                       abbr_grant_or_revoke

ALTERDEFAULTPRIVILEGESFORROLEUSER,role_nameINSCHEMA,schema_nameabbr_grant_or_revoke

abbr_grant_or_revoke

abbr_grant_or_revoke ::= a_grant_table
                         | a_grant_seq
                         | a_grant_func
                         | a_grant_type
                         | a_grant_schema
                         | a_revoke_table
                         | a_revoke_seq
                         | a_revoke_func
                         | a_revoke_type
                         | a_revoke_schema

a_grant_tablea_grant_seqa_grant_funca_grant_typea_grant_schemaa_revoke_tablea_revoke_seqa_revoke_funca_revoke_typea_revoke_schema

a_grant_table

a_grant_table ::= GRANT { grant_table_priv [ , ... ]
                          | ALL [ PRIVILEGES ] } ON TABLES TO
                  grant_role_spec [ , ... ] [ WITH GRANT OPTION ]

GRANT,grant_table_privALLPRIVILEGESONTABLESTO,grant_role_specWITHGRANTOPTION

grant_table_priv

grant_table_priv ::= SELECT
                     | INSERT
                     | UPDATE
                     | DELETE
                     | TRUNCATE
                     | REFERENCES
                     | TRIGGER

SELECTINSERTUPDATEDELETETRUNCATEREFERENCESTRIGGER

a_grant_seq

a_grant_seq ::= GRANT { grant_seq_priv [ , ... ]
                        | ALL [ PRIVILEGES ] } ON SEQUENCES TO
                grant_role_spec [ , ... ] [ WITH GRANT OPTION ]

GRANT,grant_seq_privALLPRIVILEGESONSEQUENCESTO,grant_role_specWITHGRANTOPTION

grant_seq_priv

grant_seq_priv ::= USAGE | SELECT | UPDATE

USAGESELECTUPDATE

a_grant_func

a_grant_func ::= GRANT { EXECUTE | ALL [ PRIVILEGES ] } ON
                 { FUNCTIONS | ROUTINES } TO grant_role_spec [ , ... ]
                 [ WITH GRANT OPTION ]

GRANTEXECUTEALLPRIVILEGESONFUNCTIONSROUTINESTO,grant_role_specWITHGRANTOPTION

a_grant_type

a_grant_type ::= GRANT { USAGE | ALL [ PRIVILEGES ] } ON TYPES TO
                 grant_role_spec [ , ... ] [ WITH GRANT OPTION ]

GRANTUSAGEALLPRIVILEGESONTYPESTO,grant_role_specWITHGRANTOPTION

a_grant_schema

a_grant_schema ::= GRANT { USAGE | CREATE | ALL [ PRIVILEGES ] } ON
                   SCHEMAS TO grant_role_spec [ , ... ]
                   [ WITH GRANT OPTION ]

GRANTUSAGECREATEALLPRIVILEGESONSCHEMASTO,grant_role_specWITHGRANTOPTION

a_revoke_table

a_revoke_table ::= REVOKE [ GRANT OPTION FOR ]
                   { grant_table_priv [ , ... ] | ALL [ PRIVILEGES ] }
                   ON TABLES FROM grant_role_spec [ , ... ]
                   [ CASCADE | RESTRICT ]

REVOKEGRANTOPTIONFOR,grant_table_privALLPRIVILEGESONTABLESFROM,grant_role_specCASCADERESTRICT

a_revoke_seq

a_revoke_seq ::= REVOKE [ GRANT OPTION FOR ]
                 { grant_seq_priv [ , ... ] | ALL [ PRIVILEGES ] } ON
                 SEQUENCES FROM grant_role_spec [ , ... ]
                 [ CASCADE | RESTRICT ]

REVOKEGRANTOPTIONFOR,grant_seq_privALLPRIVILEGESONSEQUENCESFROM,grant_role_specCASCADERESTRICT

a_revoke_func

a_revoke_func ::= REVOKE [ GRANT OPTION FOR ]
                  { EXECUTE | ALL [ PRIVILEGES ] } ON
                  { FUNCTIONS | ROUTINES } FROM grant_role_spec
                  [ , ... ] [ CASCADE | RESTRICT ]

REVOKEGRANTOPTIONFOREXECUTEALLPRIVILEGESONFUNCTIONSROUTINESFROM,grant_role_specCASCADERESTRICT

a_revoke_type

a_revoke_type ::= REVOKE [ GRANT OPTION FOR ]
                  { USAGE | ALL [ PRIVILEGES ] } ON TYPES FROM
                  grant_role_spec [ , ... ] [ CASCADE | RESTRICT ]

REVOKEGRANTOPTIONFORUSAGEALLPRIVILEGESONTYPESFROM,grant_role_specCASCADERESTRICT

a_revoke_schema

a_revoke_schema ::= REVOKE [ GRANT OPTION FOR ]
                    { USAGE | CREATE | ALL [ PRIVILEGES ] } ON SCHEMAS
                    FROM grant_role_spec [ , ... ]
                    [ CASCADE | RESTRICT ]

REVOKEGRANTOPTIONFORUSAGECREATEALLPRIVILEGESONSCHEMASFROM,grant_role_specCASCADERESTRICT

alter_domain_default

alter_domain_default ::= ALTER DOMAIN name
                         { SET DEFAULT expression | DROP DEFAULT }

ALTERDOMAINnameSETDEFAULTexpressionDROPDEFAULT

alter_domain_rename

alter_domain_rename ::= ALTER DOMAIN name RENAME TO name

ALTERDOMAINnameRENAMETOname

alter_function

alter_function ::= ALTER FUNCTION subprogram_name (
                   [ subprogram_signature ] )
                   { special_fn_and_proc_attribute
                     | { alterable_fn_and_proc_attribute
                         | alterable_fn_only_attribute } [ ... ]
                       [ RESTRICT ] }

ALTERFUNCTIONsubprogram_name(subprogram_signature)special_fn_and_proc_attributealterable_fn_and_proc_attributealterable_fn_only_attributeRESTRICT

special_fn_and_proc_attribute

special_fn_and_proc_attribute ::= RENAME TO subprogram_name
                                  | OWNER TO
                                    { role_name
                                      | CURRENT_ROLE
                                      | CURRENT_USER
                                      | SESSION_USER }
                                  | SET SCHEMA schema_name
                                  | [ NO ] DEPENDS ON EXTENSION
                                    extension_name

RENAMETOsubprogram_nameOWNERTOrole_nameCURRENT_ROLECURRENT_USERSESSION_USERSETSCHEMAschema_nameNODEPENDSONEXTENSIONextension_name

alter_group

alter_group ::= ALTER GROUP role_specification { ADD | DROP } USER
                role_name [ , ... ]

ALTERGROUProle_specificationADDDROPUSER,role_name

alter_group_rename

alter_group_rename ::= ALTER GROUP role_name RENAME TO new_role_name

ALTERGROUProle_nameRENAMETOnew_role_name

alter_foreign_data_wrapper

alter_foreign_data_wrapper ::= ALTER FOREIGN DATA WRAPPER fdw_name
                               [ HANDLER handler_name | NO HANDLER ]
                               [ VALIDATOR validator_name
                                 | NO VALIDATOR ]
                               [ OPTIONS ( alter_fdw_options ) ]
                               [ OWNER TO new_owner ]
                               [ RENAME TO new_name ]

ALTERFOREIGNDATAWRAPPERfdw_nameHANDLERhandler_nameNOHANDLERVALIDATORvalidator_nameNOVALIDATOROPTIONS(alter_fdw_options)OWNERTOnew_ownerRENAMETOnew_name

alter_foreign_table

alter_foreign_table ::= ALTER FOREIGN TABLE [ IF EXISTS ] table_name
                        alter_foreign_table_action [ , ... ]

ALTERFOREIGNTABLEIFEXISTStable_name,alter_foreign_table_action

alter_foreign_table_action

alter_foreign_table_action ::= ADD [ COLUMN ] column_name data_type
                               [ COLLATE collation ]
                               [ alter_column_constraint [ ... ] ]
                               | RENAME TO table_name
                               | DROP [ COLUMN ] column_name
                                 [ RESTRICT | CASCADE ]
                               | OWNER TO new_owner
                               | OPTIONS ( alter_fdw_options )

ADDCOLUMNcolumn_namedata_typeCOLLATEcollationalter_column_constraintRENAMETOtable_nameDROPCOLUMNcolumn_nameRESTRICTCASCADEOWNERTOnew_ownerOPTIONS(alter_fdw_options)

alter_group

alter_group ::= ALTER GROUP role_specification { ADD | DROP } USER
                role_name [ , ... ]

ALTERGROUProle_specificationADDDROPUSER,role_name

alter_group_rename

alter_group_rename ::= ALTER GROUP role_name RENAME TO new_role_name

ALTERGROUProle_nameRENAMETOnew_role_name

alter_policy

alter_policy ::= ALTER POLICY name ON table_name
                 [ TO { role_name
                        | PUBLIC
                        | CURRENT_USER
                        | SESSION_USER } [ , ... ] ]
                 [ USING ( using_expression ) ]
                 [ WITH CHECK ( check_expression ) ]

ALTERPOLICYnameONtable_nameTO,role_namePUBLICCURRENT_USERSESSION_USERUSING(using_expression)WITHCHECK(check_expression)

alter_policy_rename

alter_policy_rename ::= ALTER POLICY name ON table_name RENAME TO
                        new_name

ALTERPOLICYnameONtable_nameRENAMETOnew_name

alter_procedure

alter_procedure ::= ALTER PROCEDURE subprogram_name (
                    [ subprogram_signature ] )
                    { special_fn_and_proc_attribute
                      | alterable_fn_and_proc_attribute [ ... ]
                        [ RESTRICT ] }

ALTERPROCEDUREsubprogram_name(subprogram_signature)special_fn_and_proc_attributealterable_fn_and_proc_attributeRESTRICT

alter_role

alter_role ::= ALTER ROLE role_specification
               [ [ WITH ] alter_role_option [ , ... ] ]

ALTERROLErole_specificationWITH,alter_role_option

alter_role_option

alter_role_option ::= SUPERUSER
                      | NOSUPERUSER
                      | CREATEDB
                      | NOCREATEDB
                      | CREATEROLE
                      | NOCREATEROLE
                      | INHERIT
                      | NOINHERIT
                      | LOGIN
                      | NOLOGIN
                      | CONNECTION LIMIT connlimit
                      | [ ENCRYPTED ] PASSWORD  ' password '
                      | PASSWORD NULL
                      | VALID UNTIL  ' timestamp '

SUPERUSERNOSUPERUSERCREATEDBNOCREATEDBCREATEROLENOCREATEROLEINHERITNOINHERITLOGINNOLOGINCONNECTIONLIMITconnlimitENCRYPTEDPASSWORD password PASSWORDNULLVALIDUNTIL timestamp

role_specification

role_specification ::= role_name | CURRENT_USER | SESSION_USER

role_nameCURRENT_USERSESSION_USER

alter_role_rename

alter_role_rename ::= ALTER ROLE role_name RENAME TO new_role_name

ALTERROLErole_nameRENAMETOnew_role_name

new_role_name

new_role_name ::= name

name

alter_role_config

alter_role_config ::= ALTER ROLE { role_specification | ALL }
                      [ IN DATABASE database_name ] config_setting

ALTERROLErole_specificationALLINDATABASEdatabase_nameconfig_setting

config_setting

config_setting ::= SET config_param { TO | = }
                   { config_value | DEFAULT }
                   | SET config_param FROM CURRENT
                   | RESET config_param
                   | RESET ALL

SETconfig_paramTO=config_valueDEFAULTSETconfig_paramFROMCURRENTRESETconfig_paramRESETALL

config_param

config_param ::= '<Text Literal>'

<Text Literal>

config_value

config_value ::= '<Text Literal>'

<Text Literal>

alter_sequence

alter_sequence ::= ALTER SEQUENCE [ IF EXISTS ] sequence_name
                   alter_sequence_options

ALTERSEQUENCEIFEXISTSsequence_namealter_sequence_options

alter_sequence_options

alter_sequence_options ::= [ AS seq_data_type ]
                           [ INCREMENT [ BY ] increment ]
                           [ MINVALUE minvalue | NO MINVALUE ]
                           [ MAXVALUE maxvalue | NO MAXVALUE ]
                           [ START [ WITH ] start ]
                           [ RESTART [ [ WITH ] restart ] ]
                           [ CACHE cache ]
                           [ OWNED BY table_name.table_column | NONE ]

ASseq_data_typeINCREMENTBYincrementMINVALUEminvalueNOMINVALUEMAXVALUEmaxvalueNOMAXVALUESTARTWITHstartRESTARTWITHrestartCACHEcacheOWNED BYtable_name.table_columnNONE

seq_data_type

seq_data_type ::= 'smallint' | 'integer' | 'bigint'

smallintintegerbigint

restart

restart ::= '<Integer Literal>'

<Integer Literal>

alter_server

alter_server ::= ALTER SERVER server_name [ VERSION server_version ]
                 [ OPTIONS ( alter_fdw_options ) ]
                 [ OWNER TO new_owner ]

ALTERSERVERserver_nameVERSIONserver_versionOPTIONS(alter_fdw_options)OWNERTOnew_owner

alter_table

alter_table ::= ALTER TABLE table_expr alter_table_action [ , ... ]

ALTERTABLEtable_expr,alter_table_action

alter_table_action

alter_table_action ::= ADD [ COLUMN ] column_name data_type
                       [ alter_column_constraint [ ... ] ]
                       | RENAME TO table_name
                       | DROP [ COLUMN ] column_name
                         [ RESTRICT | CASCADE ]
                       | ADD alter_table_constraint
                       | DROP CONSTRAINT constraint_name
                         [ RESTRICT | CASCADE ]
                       | RENAME [ COLUMN ] column_name TO column_name
                       | DISABLE ROW LEVEL SECURITY
                       | ENABLE ROW LEVEL SECURITY
                       | FORCE ROW LEVEL SECURITY
                       | NO FORCE ROW LEVEL SECURITY

ADDCOLUMNcolumn_namedata_typealter_column_constraintRENAMETOtable_nameDROPCOLUMNcolumn_nameRESTRICTCASCADEADDalter_table_constraintDROPCONSTRAINTconstraint_nameRESTRICTCASCADERENAMECOLUMNcolumn_nameTOcolumn_nameDISABLEROWLEVELSECURITYENABLEROWLEVELSECURITYFORCEROWLEVELSECURITYNOFORCEROWLEVELSECURITY

alter_table_constraint

alter_table_constraint ::= [ CONSTRAINT constraint_name ]
                           { CHECK ( expression )
                             | UNIQUE ( column_names )
                               index_parameters
                             | FOREIGN KEY ( column_names )
                               references_clause }
                           [ DEFERRABLE | NOT DEFERRABLE ]
                           [ INITIALLY DEFERRED
                             | INITIALLY IMMEDIATE ]

CONSTRAINTconstraint_nameCHECK(expression)UNIQUE(column_names)index_parametersFOREIGNKEY(column_names)references_clauseDEFERRABLENOTDEFERRABLEINITIALLYDEFERREDINITIALLYIMMEDIATE

alter_column_constraint

alter_column_constraint ::= [ CONSTRAINT constraint_name ]
                            { NOT NULL
                              | NULL
                              | CHECK ( expression )
                              | DEFAULT expression
                              | UNIQUE index_parameters
                              | references_clause }
                            [ DEFERRABLE | NOT DEFERRABLE ]
                            [ INITIALLY DEFERRED
                              | INITIALLY IMMEDIATE ]

CONSTRAINTconstraint_nameNOTNULLNULLCHECK(expression)DEFAULTexpressionUNIQUEindex_parametersreferences_clauseDEFERRABLENOTDEFERRABLEINITIALLYDEFERREDINITIALLYIMMEDIATE

alter_user

alter_user ::= ALTER USER role_specification
               [ [ WITH ] alter_role_option [ , ... ] ]

ALTERUSERrole_specificationWITH,alter_role_option

alter_user_rename

alter_user_rename ::= ALTER USER role_name RENAME TO new_role_name

ALTERUSERrole_nameRENAMETOnew_role_name

alter_user_config

alter_user_config ::= ALTER USER { role_specification | ALL }
                      [ IN DATABASE database_name ] config_setting

ALTERUSERrole_specificationALLINDATABASEdatabase_nameconfig_setting

analyze

analyze ::= ANALYZE [ VERBOSE ] [ table_and_columns [ , ... ] ]

ANALYZEVERBOSE,table_and_columns

table_and_columns

table_and_columns ::= table_name [ ( column_name [ , ... ] ) ]

table_name(,column_name)

begin

begin ::= BEGIN [ TRANSACTION | WORK ] [ transaction_mode [ ... ] ]

BEGINTRANSACTIONWORKtransaction_mode

call_procedure

call_procedure ::= CALL subprogram_name ( [ subprogram_arg [ , ... ] ]
                   )

CALLsubprogram_name(,subprogram_arg)

subprogram_arg

subprogram_arg ::= [ arg_name => ] expression

arg_name=>expression

comment_on

comment_on ::= COMMENT ON
               { ACCESS METHOD access_method_name
                 | AGGREGATE aggregate_name ( aggregate_signature )
                 | CAST ( source_type AS target_type )
                 | COLLATION object_name
                 | COLUMN relation_name . column_name
                 | CONSTRAINT constraint_name ON table_name
                 | CONSTRAINT constraint_name ON DOMAIN domain_name
                 | CONVERSION object_name
                 | DATABASE object_name
                 | DOMAIN object_name
                 | EXTENSION object_name
                 | EVENT TRIGGER object_name
                 | FOREIGN DATA WRAPPER object_name
                 | FOREIGN TABLE object_name
                 | FUNCTION subprogram_name ( [ subprogram_signature ]
                   ) | INDEX object_name
                 | LARGE OBJECT large_object_oid
                 | MATERIALIZED VIEW object_name
                 | OPERATOR operator_name ( operator_signature )
                 | OPERATOR CLASS object_name USING index_method
                 | OPERATOR FAMILY object_name USING index_method
                 | POLICY policy_name ON table_name
                 | [ PROCEDURAL ] LANGUAGE object_name
                 | PROCEDURE subprogram_name (
                   [ subprogram_signature ] )
                 | PUBLICATION object_name
                 | ROLE object_name
                 | ROUTINE subprogram_name ( [ subprogram_signature ]
                   ) | RULE rule_name ON table_name
                 | SCHEMA object_name
                 | SEQUENCE object_name
                 | SERVER object_name
                 | STATISTICS object_name
                 | SUBSCRIPTION object_name
                 | TABLE object_name
                 | TABLESPACE object_name
                 | TEXT SEARCH CONFIGURATION object_name
                 | TEXT SEARCH DICTIONARY object_name
                 | TEXT SEARCH PARSER object_name
                 | TEXT SEARCH TEMPLATE object_name
                 | TRIGGER trigger_name ON table_name
                 | TYPE object_name
                 | VIEW object_name } IS { '<Text Literal>' | NULL }

COMMENTONACCESSMETHODaccess_method_nameAGGREGATEaggregate_name(aggregate_signature)CAST(source_typeAStarget_type)COLLATIONobject_nameCOLUMNrelation_name.column_nameCONSTRAINTconstraint_nameONtable_nameCONSTRAINTconstraint_nameONDOMAINdomain_nameCONVERSIONobject_nameDATABASEobject_nameDOMAINobject_nameEXTENSIONobject_nameEVENTTRIGGERobject_nameFOREIGNDATAWRAPPERobject_nameFOREIGNTABLEobject_nameFUNCTIONsubprogram_name(subprogram_signature)INDEXobject_nameLARGEOBJECTlarge_object_oidMATERIALIZEDVIEWobject_nameOPERATORoperator_name(operator_signature)OPERATORCLASSobject_nameUSINGindex_methodOPERATORFAMILYobject_nameUSINGindex_methodPOLICYpolicy_nameONtable_namePROCEDURALLANGUAGEobject_namePROCEDUREsubprogram_name(subprogram_signature)PUBLICATIONobject_nameROLEobject_nameROUTINEsubprogram_name(subprogram_signature)RULErule_nameONtable_nameSCHEMAobject_nameSEQUENCEobject_nameSERVERobject_nameSTATISTICSobject_nameSUBSCRIPTIONobject_nameTABLEobject_nameTABLESPACEobject_nameTEXTSEARCHCONFIGURATIONobject_nameTEXTSEARCHDICTIONARYobject_nameTEXTSEARCHPARSERobject_nameTEXTSEARCHTEMPLATEobject_nameTRIGGERtrigger_nameONtable_nameTYPEobject_nameVIEWobject_nameIS<Text Literal>NULL

commit

commit ::= COMMIT [ TRANSACTION | WORK ]

COMMITTRANSACTIONWORK

copy_from

copy_from ::= COPY table_name [ ( column_name [ , ... ] ) ]  FROM
              { 'filename' | PROGRAM 'command' | STDIN }
              [ [ WITH ] ( option [ , ... ] ) ]

COPYtable_name(,column_name)FROMfilenamePROGRAMcommandSTDINWITH(,option)

copy_to

copy_to ::= COPY { table_name [ ( column_names ) ] | ( query ) }  TO
            { 'filename' | PROGRAM 'command' | STDOUT }
            [ [ WITH ] ( option [ , ... ] ) ]

COPYtable_name(column_names)(query)TOfilenamePROGRAMcommandSTDOUTWITH(,option)

copy_option

copy_option ::= FORMAT format_name
                | OIDS [ boolean ]
                | FREEZE [ boolean ]
                | DELIMITER 'delimiter_character'
                | NULL 'null_string'
                | HEADER [ boolean ]
                | QUOTE 'quote_character'
                | ESCAPE 'escape_character'
                | FORCE_QUOTE { ( column_names ) | * }
                | FORCE_NOT_NULL ( column_names )
                | FORCE_NULL ( column_names )
                | ENCODING 'encoding_name'
                | ROWS_PER_TRANSACTION integer
                | DISABLE_FK_CHECK
                | REPLACE
                | SKIP integer

FORMATformat_nameOIDSbooleanFREEZEbooleanDELIMITERdelimiter_characterNULLnull_stringHEADERbooleanQUOTEquote_characterESCAPEescape_characterFORCE_QUOTE(column_names)*FORCE_NOT_NULL(column_names)FORCE_NULL(column_names)ENCODINGencoding_nameROWS_PER_TRANSACTIONintegerDISABLE_FK_CHECKREPLACESKIPinteger

create_aggregate

create_aggregate ::= create_aggregate_normal
                     | create_aggregate_order_by
                     | create_aggregate_old

create_aggregate_normalcreate_aggregate_order_bycreate_aggregate_old

create_aggregate_normal

create_aggregate_normal ::= CREATE AGGREGATE aggregate_name (
                            { aggregate_arg [ , ... ] | * } ) ( SFUNC
                            = sfunc , STYPE = state_data_type
                            [ , aggregate_normal_option [ ... ] ] )

CREATEAGGREGATEaggregate_name(,aggregate_arg*)(SFUNC=sfunc,STYPE=state_data_type,aggregate_normal_option)

create_aggregate_order_by

create_aggregate_order_by ::= CREATE AGGREGATE aggregate_name (
                              [ aggregate_arg [ , ... ] ] ORDER BY
                              aggregate_arg [ , ... ] ) ( SFUNC =
                              sfunc , STYPE = state_data_type
                              [ , aggregate_order_by_option [ ... ] ]
                              )

CREATEAGGREGATEaggregate_name(,aggregate_argORDERBY,aggregate_arg)(SFUNC=sfunc,STYPE=state_data_type,aggregate_order_by_option)

create_aggregate_old

create_aggregate_old ::= CREATE AGGREGATE aggregate_name ( BASETYPE =
                         base_type , SFUNC = sfunc , STYPE =
                         state_data_type
                         [ , aggregate_old_option [ ... ] ] )

CREATEAGGREGATEaggregate_name(BASETYPE=base_type,SFUNC=sfunc,STYPE=state_data_type,aggregate_old_option)

aggregate_arg

aggregate_arg ::= [ aggregate_arg_mode ] [ arg_name ] arg_type

aggregate_arg_modearg_namearg_type

aggregate_normal_option

aggregate_normal_option ::= SSPACE = state_data_size
                            | FINALFUNC = ffunc
                            | FINALFUNC_EXTRA
                            | FINALFUNC_MODIFY =
                              { READ_ONLY | SHAREABLE | READ_WRITE }
                            | COMBINEFUNC = combinefunc
                            | SERIALFUNC = serialfunc
                            | DESERIALFUNC = deserialfunc
                            | INITCOND = initial_condition
                            | MSFUNC = msfunc
                            | MINVFUNC = minvfunc
                            | MSTYPE = mstate_data_type
                            | MSSPACE = mstate_data_size
                            | MFINALFUNC = mffunc
                            | MFINALFUNC_EXTRA
                            | MFINALFUNC_MODIFY =
                              { READ_ONLY | SHAREABLE | READ_WRITE }
                            | MINITCOND = minitial_condition
                            | SORTOP = sort_operator
                            | PARALLEL =
                              { SAFE | RESTRICTED | UNSAFE }

SSPACE=state_data_sizeFINALFUNC=ffuncFINALFUNC_EXTRAFINALFUNC_MODIFY=READ_ONLYSHAREABLEREAD_WRITECOMBINEFUNC=combinefuncSERIALFUNC=serialfuncDESERIALFUNC=deserialfuncINITCOND=initial_conditionMSFUNC=msfuncMINVFUNC=minvfuncMSTYPE=mstate_data_typeMSSPACE=mstate_data_sizeMFINALFUNC=mffuncMFINALFUNC_EXTRAMFINALFUNC_MODIFY=READ_ONLYSHAREABLEREAD_WRITEMINITCOND=minitial_conditionSORTOP=sort_operatorPARALLEL=SAFERESTRICTEDUNSAFE

aggregate_order_by_option

aggregate_order_by_option ::= SSPACE = state_data_size
                              | FINALFUNC = ffunc
                              | FINALFUNC_EXTRA
                              | FINALFUNC_MODIFY =
                                { READ_ONLY | SHAREABLE | READ_WRITE }
                              | INITCOND = initial_condition
                              | PARALLEL =
                                { SAFE | RESTRICTED | UNSAFE }
                              | HYPOTHETICAL

SSPACE=state_data_sizeFINALFUNC=ffuncFINALFUNC_EXTRAFINALFUNC_MODIFY=READ_ONLYSHAREABLEREAD_WRITEINITCOND=initial_conditionPARALLEL=SAFERESTRICTEDUNSAFEHYPOTHETICAL

aggregate_old_option

aggregate_old_option ::= SSPACE = state_data_size
                         | FINALFUNC = ffunc
                         | FINALFUNC_EXTRA
                         | FINALFUNC_MODIFY =
                           { READ_ONLY | SHAREABLE | READ_WRITE }
                         | COMBINEFUNC = combinefunc
                         | SERIALFUNC = serialfunc
                         | DESERIALFUNC = deserialfunc
                         | INITCOND = initial_condition
                         | MSFUNC = msfunc
                         | MINVFUNC = minvfunc
                         | MSTYPE = mstate_data_type
                         | MSSPACE = mstate_data_size
                         | MFINALFUNC = mffunc
                         | MFINALFUNC_EXTRA
                         | MFINALFUNC_MODIFY =
                           { READ_ONLY | SHAREABLE | READ_WRITE }
                         | MINITCOND = minitial_condition
                         | SORTOP = sort_operator

SSPACE=state_data_sizeFINALFUNC=ffuncFINALFUNC_EXTRAFINALFUNC_MODIFY=READ_ONLYSHAREABLEREAD_WRITECOMBINEFUNC=combinefuncSERIALFUNC=serialfuncDESERIALFUNC=deserialfuncINITCOND=initial_conditionMSFUNC=msfuncMINVFUNC=minvfuncMSTYPE=mstate_data_typeMSSPACE=mstate_data_sizeMFINALFUNC=mffuncMFINALFUNC_EXTRAMFINALFUNC_MODIFY=READ_ONLYSHAREABLEREAD_WRITEMINITCOND=minitial_conditionSORTOP=sort_operator

create_cast

create_cast ::= create_cast_with_function
                | create_cast_without_function
                | create_cast_with_inout

create_cast_with_functioncreate_cast_without_functioncreate_cast_with_inout

create_cast_with_function

create_cast_with_function ::= CREATE CAST ( cast_signature ) WITH
                              FUNCTION subprogram_name
                              [ ( subprogram_signature ) ]
                              [ AS ASSIGNMENT | AS IMPLICIT ]

CREATECAST(cast_signature)WITHFUNCTIONsubprogram_name(subprogram_signature)ASASSIGNMENTASIMPLICIT

create_cast_without_function

create_cast_without_function ::= CREATE CAST ( cast_signature )
                                 WITHOUT FUNCTION
                                 [ AS ASSIGNMENT | AS IMPLICIT ]

CREATECAST(cast_signature)WITHOUTFUNCTIONASASSIGNMENTASIMPLICIT

create_cast_with_inout

create_cast_with_inout ::= CREATE CAST ( cast_signature ) WITH INOUT
                           [ AS ASSIGNMENT | AS IMPLICIT ]

CREATECAST(cast_signature)WITHINOUTASASSIGNMENTASIMPLICIT

cast_signature

cast_signature ::= source_type AS target_type

source_typeAStarget_type

create_database

create_database ::= CREATE DATABASE name [ create_database_options ]

CREATEDATABASEnamecreate_database_options

create_database_options

create_database_options ::= [ WITH ] [ OWNER [ = ] user_name ]
                            [ TEMPLATE [ = ] template ]
                            [ ENCODING [ = ] encoding ]
                            [ LC_COLLATE [ = ] lc_collate ]
                            [ LC_CTYPE [ = ] lc_ctype ]
                            [ ALLOW_CONNECTIONS [ = ] allowconn ]
                            [ CONNECTION LIMIT [ = ] connlimit ]
                            [ IS_TEMPLATE [ = ] istemplate ]
                            [ COLOCATED [ = ] { 'true' | 'false' } ]

WITHOWNER=user_nameTEMPLATE=templateENCODING=encodingLC_COLLATE=lc_collateLC_CTYPE=lc_ctypeALLOW_CONNECTIONS=allowconnCONNECTIONLIMIT=connlimitIS_TEMPLATE=istemplateCOLOCATED=truefalse

create_domain

create_domain ::= CREATE DOMAIN name [ AS ] data_type
                  [ DEFAULT expression ]
                  [ [ domain_constraint [ ... ] ] ]

CREATEDOMAINnameASdata_typeDEFAULTexpressiondomain_constraint

domain_constraint

domain_constraint ::= [ CONSTRAINT constraint_name ]
                      { NOT NULL | NULL | CHECK ( expression ) }

CONSTRAINTconstraint_nameNOTNULLNULLCHECK(expression)

create_extension

create_extension ::= CREATE EXTENSION [ IF NOT EXISTS ] extension_name
                     [ WITH ] [ SCHEMA schema_name ]
                     [ VERSION version ] [ CASCADE ]

CREATEEXTENSIONIFNOTEXISTSextension_nameWITHSCHEMAschema_nameVERSIONversionCASCADE

create_function

create_function ::= CREATE [ OR REPLACE ] FUNCTION subprogram_name (
                    [ arg_decl_with_dflt [ , ... ] ] )
                    { RETURNS data_type
                      | RETURNS TABLE ( { column_name data_type }
                        [ , ... ] ) }
                    { unalterable_fn_attribute
                      | alterable_fn_only_attribute
                      | alterable_fn_and_proc_attribute } [ ... ]

CREATEORREPLACEFUNCTIONsubprogram_name(,arg_decl_with_dflt)RETURNSdata_typeRETURNSTABLE(,column_namedata_type)unalterable_fn_attributealterable_fn_only_attributealterable_fn_and_proc_attribute

arg_decl_with_dflt

arg_decl_with_dflt ::= arg_decl [ { DEFAULT | = } expression ]

arg_declDEFAULT=expression

arg_decl

arg_decl ::= [ arg_name ] [ arg_mode ] arg_type

arg_namearg_modearg_type

subprogram_signature

subprogram_signature ::= arg_decl [ , ... ]

,arg_decl

fn_invocation

fn_invocation ::= subprogram_name ( [ subprogram_arg [ , ... ] ] )

subprogram_name(,subprogram_arg)

subprogram_call_signature

subprogram_call_signature ::= arg_type [ , ... ]

,arg_type

unalterable_fn_attribute

unalterable_fn_attribute ::= WINDOW
                             | LANGUAGE lang_name
                             | AS implementation_definition

WINDOWLANGUAGElang_nameASimplementation_definition

lang_name

lang_name ::= SQL | PLPGSQL | C

SQLPLPGSQLC

implementation_definition

implementation_definition ::= ' sql_stmt_list '
                              | ' plpgsql_block_stmt '
                              | ' obj_file ' [ , ' link_symbol ' ]

'sql_stmt_list''plpgsql_block_stmt''obj_file','link_symbol'

sql_stmt_list

sql_stmt_list ::= sql_stmt ; [ sql_stmt ... ]

sql_stmt;sql_stmt;

alterable_fn_and_proc_attribute

alterable_fn_and_proc_attribute ::= SET configuration_parameter
                                    { TO value
                                      | = value
                                      | FROM CURRENT }
                                    | RESET configuration_parameter
                                    | RESET ALL
                                    | [ EXTERNAL ] SECURITY
                                      { INVOKER | DEFINER }

SETconfiguration_parameterTOvalue=valueFROMCURRENTRESETconfiguration_parameterRESETALLEXTERNALSECURITYINVOKERDEFINER

alterable_fn_only_attribute

alterable_fn_only_attribute ::= volatility
                                | on_null_input
                                | PARALLEL parallel_mode
                                | [ NOT ] LEAKPROOF
                                | COST int_literal
                                | ROWS int_literal

volatilityon_null_inputPARALLELparallel_modeNOTLEAKPROOFCOSTint_literalROWSint_literal

volatility

volatility ::= IMMUTABLE | STABLE | VOLATILE

IMMUTABLESTABLEVOLATILE

on_null_input

on_null_input ::= CALLED ON NULL INPUT
                  | RETURNS NULL ON NULL INPUT
                  | STRICT

CALLEDONNULLINPUTRETURNSNULLONNULLINPUTSTRICT

parallel_mode

parallel_mode ::= UNSAFE | RESTRICTED | SAFE

UNSAFERESTRICTEDSAFE

create_foreign_data_wrapper

create_foreign_data_wrapper ::= CREATE FOREIGN DATA WRAPPER fdw_name
                                [ HANDLER handler_name | NO HANDLER ]
                                [ VALIDATOR validator_name
                                  | NO VALIDATOR ]
                                [ OPTIONS ( fdw_options ) ]

CREATEFOREIGNDATAWRAPPERfdw_nameHANDLERhandler_nameNOHANDLERVALIDATORvalidator_nameNOVALIDATOROPTIONS(fdw_options)

create_foreign_table

create_foreign_table ::= CREATE FOREIGN TABLE [ IF NOT EXISTS ]
                         table_name ( [ foreign_table_elem [ , ... ] ]
                         ) SERVER server_name
                         [ OPTIONS ( fdw_options ) ]

CREATEFOREIGNTABLEIFNOTEXISTStable_name(,foreign_table_elem)SERVERserver_nameOPTIONS(fdw_options)

foreign_table_elem

foreign_table_elem ::= column_name data_type
                       [ OPTIONS ( fdw_options ) ]
                       [ COLLATE collation ]
                       [ column_constraint [ ... ] ]
                       | table_constraint

column_namedata_typeOPTIONS(fdw_options)COLLATEcollationcolumn_constrainttable_constraint

create_group

create_group ::= CREATE GROUP role_name
                 [ [ WITH ] role_option [ , ... ] ]

CREATEGROUProle_nameWITH,role_option

create_index

create_index ::= CREATE [ UNIQUE ] INDEX [ NONCONCURRENTLY ]
                 [ [ IF NOT EXISTS ] name ] ON [ ONLY ] table_name
                 [ USING access_method_name ] ( index_elem [ , ... ] )
                  [ INCLUDE ( column_name [ , ... ] ) ]
                 [ TABLESPACE tablespace_name ]
                 [ WHERE boolean_expression ]

CREATEUNIQUEINDEXCONCURRENTLYNONCONCURRENTLYIFNOTEXISTSnameONONLYtable_nameUSINGaccess_method_name(,index_elem)INCLUDE(,column_name)TABLESPACEtablespace_nameWHEREboolean_expression

index_elem

index_elem ::= { column_name | ( expression ) }
               [ operator_class_name ] [ HASH | ASC | DESC ]
               [ NULLS { FIRST | LAST } ]

column_name(expression)operator_class_nameHASHASCDESCNULLSFIRSTLAST

create_matview

create_matview ::= CREATE MATERIALIZED VIEW [ IF NOT EXISTS ]
                   matview_name [ ( column_name [ , ... ] ) ]
                   [ WITH ( storage_parameters ) ]
                   [ TABLESPACE tablespace ]  AS query
                   [ WITH [ NO ] DATA ]

CREATEMATERIALIZEDVIEWIFNOTEXISTSmatview_name(,column_name)WITH(storage_parameters)TABLESPACEtablespaceASqueryWITHNODATA

create_operator

create_operator ::= CREATE OPERATOR operator_name (
                    { FUNCTION = subprogram_name
                      | PROCEDURE = subprogram_name }
                    [ , operator_option [ ... ] ] )

CREATEOPERATORoperator_name(FUNCTION=subprogram_namePROCEDURE=subprogram_name,operator_option)

operator_option

operator_option ::= LEFTARG = left_type
                    | RIGHTARG = right_type
                    | COMMUTATOR = com_op
                    | NEGATOR = neg_op
                    | RESTRICT = res_proc
                    | JOIN = join_proc
                    | HASHES
                    | MERGES

LEFTARG=left_typeRIGHTARG=right_typeCOMMUTATOR=com_opNEGATOR=neg_opRESTRICT=res_procJOIN=join_procHASHESMERGES

create_operator_class

create_operator_class ::= CREATE OPERATOR CLASS operator_class_name
                          [ DEFAULT ] FOR TYPE data_type USING
                          index_method AS operator_class_as [ , ... ]

CREATEOPERATORCLASSoperator_class_nameDEFAULTFORTYPEdata_typeUSINGindex_methodAS,operator_class_as

operator_class_as

operator_class_as ::= OPERATOR strategy_number operator_name
                      [ ( operator_signature ) ] [ FOR SEARCH ]
                      | FUNCTION support_number
                        [ ( op_type [ , ... ] ) ] subprogram_name (
                        subprogram_signature )
                      | STORAGE storage_type

OPERATORstrategy_numberoperator_name(operator_signature)FORSEARCHFUNCTIONsupport_number(,op_type)subprogram_name(subprogram_signature)STORAGEstorage_type

create_policy

create_policy ::= CREATE POLICY name ON table_name
                  [ AS { PERMISSIVE | RESTRICTIVE } ]
                  [ FOR { ALL | SELECT | INSERT | UPDATE | DELETE } ]
                  [ TO { role_name
                         | PUBLIC
                         | CURRENT_USER
                         | SESSION_USER } [ , ... ] ]
                  [ USING ( using_expression ) ]
                  [ WITH CHECK ( check_expression ) ]

CREATEPOLICYnameONtable_nameASPERMISSIVERESTRICTIVEFORALLSELECTINSERTUPDATEDELETETO,role_namePUBLICCURRENT_USERSESSION_USERUSING(using_expression)WITHCHECK(check_expression)

create_procedure

create_procedure ::= CREATE [ OR REPLACE ] PROCEDURE subprogram_name (
                     [ arg_decl_with_dflt [ , ... ] ] )
                     { unalterable_proc_attribute
                       | alterable_fn_and_proc_attribute } [ ... ]

CREATEORREPLACEPROCEDUREsubprogram_name(,arg_decl_with_dflt)unalterable_proc_attributealterable_fn_and_proc_attribute

unalterable_proc_attribute

unalterable_proc_attribute ::= [ LANGUAGE lang_name
                                 | AS implementation_definition ]

LANGUAGElang_nameASimplementation_definition

create_rule

create_rule ::= CREATE [ OR REPLACE ] RULE rule_name AS ON rule_event
                TO table_name [ WHERE boolean_expression ] DO
                [ ALSO | INSTEAD ] { NOTHING
                                     | command
                                     | ( command [ ; ... ] ) }

CREATEORREPLACERULErule_nameASONrule_eventTOtable_nameWHEREboolean_expressionDOALSOINSTEADNOTHINGcommand(;command)

rule_event

rule_event ::= SELECT | INSERT | UPDATE | DELETE

SELECTINSERTUPDATEDELETE

command

command ::= SELECT | INSERT | UPDATE | DELETE | NOTIFY

SELECTINSERTUPDATEDELETENOTIFY

create_role

create_role ::= CREATE ROLE role_name
                [ [ WITH ] role_option [ , ... ] ]

CREATEROLErole_nameWITH,role_option

role_option

role_option ::= SUPERUSER
                | NOSUPERUSER
                | CREATEDB
                | NOCREATEDB
                | CREATEROLE
                | NOCREATEROLE
                | INHERIT
                | NOINHERIT
                | LOGIN
                | NOLOGIN
                | CONNECTION LIMIT connlimit
                | [ ENCRYPTED ] PASSWORD  ' password '
                | PASSWORD NULL
                | VALID UNTIL  ' timestamp '
                | IN ROLE role_name [ , ... ]
                | IN GROUP role_name [ , ... ]
                | ROLE role_name [ , ... ]
                | ADMIN role_name [ , ... ]
                | USER role_name [ , ... ]
                | SYSID uid

SUPERUSERNOSUPERUSERCREATEDBNOCREATEDBCREATEROLENOCREATEROLEINHERITNOINHERITLOGINNOLOGINCONNECTIONLIMITconnlimitENCRYPTEDPASSWORD password PASSWORDNULLVALIDUNTIL timestamp INROLE,role_nameINGROUP,role_nameROLE,role_nameADMIN,role_nameUSER,role_nameSYSIDuid

role_name

role_name ::= name

name

password

password ::= '<Text Literal>'

<Text Literal>

timestamp

timestamp ::= '<DateTime Literal>'

<DateTime Literal>

connlimit

connlimit ::= '<Integer Literal>'

<Integer Literal>

uid

uid ::= '<Text Literal>'

<Text Literal>

create_schema_name

create_schema_name ::= CREATE SCHEMA [ IF NOT EXISTS ] schema_name
                       [ AUTHORIZATION role_specification ]
                       [ schema_element [ ... ] ]

CREATESCHEMAIFNOTEXISTSschema_nameAUTHORIZATIONrole_specificationschema_element

create_schema_role

create_schema_role ::= CREATE SCHEMA [ IF NOT EXISTS ] AUTHORIZATION
                       role_specification [ schema_element [ ... ] ]

CREATESCHEMAIFNOTEXISTSAUTHORIZATIONrole_specificationschema_element

schema_element

schema_element ::= '<YSQL DDL statement>'

<YSQL DDL statement>

create_sequence

create_sequence ::= CREATE SEQUENCE [ IF NOT EXISTS ] sequence_name
                    sequence_options

CREATESEQUENCEIFNOTEXISTSsequence_namesequence_options

sequence_name

sequence_name ::= qualified_name

qualified_name

sequence_options

sequence_options ::= [ INCREMENT [ BY ] increment ]
                     [ MINVALUE minvalue | NO MINVALUE ]
                     [ MAXVALUE maxvalue | NO MAXVALUE ]
                     [ START [ WITH ] start ] [ CACHE cache ]
                     [ [ NO ] CYCLE ]

INCREMENTBYincrementMINVALUEminvalueNOMINVALUEMAXVALUEmaxvalueNOMAXVALUESTARTWITHstartCACHEcacheNOCYCLE

increment

increment ::= '<Integer Literal>'

<Integer Literal>

minvalue

minvalue ::= '<Integer Literal>'

<Integer Literal>

maxvalue

maxvalue ::= '<Integer Literal>'

<Integer Literal>

start

start ::= '<Integer Literal>'

<Integer Literal>

cache

cache ::= '<Integer Literal>'

<Integer Literal>

create_server

create_server ::= CREATE SERVER [ IF NOT EXISTS ] server_name
                  [ TYPE server_type ] [ VERSION server_version ]
                  FOREIGN DATA WRAPPER fdw_name
                  [ OPTIONS ( fdw_options ) ]

CREATESERVERIFNOTEXISTSserver_nameTYPEserver_typeVERSIONserver_versionFOREIGNDATAWRAPPERfdw_nameOPTIONS(fdw_options)

create_table

create_table ::= CREATE [ TEMPORARY | TEMP ] TABLE [ IF NOT EXISTS ]
                 table_name ( [ table_elem [ , ... ] ] )
                 [ WITH ( { COLOCATED = { 'true' | 'false' }
                            | storage_parameters } )
                   | WITHOUT OIDS ]  [ TABLESPACE tablespace_name ]
                 [ SPLIT { INTO integer TABLETS
                           | AT VALUES ( split_row [ , ... ] ) } ]

CREATETEMPORARYTEMPTABLEIFNOTEXISTStable_name(,table_elem)WITH(COLOCATED=truefalsestorage_parameters)WITHOUTOIDSTABLESPACEtablespace_nameSPLITINTOintegerTABLETSATVALUES(,split_row)

split_row

split_row ::= ( column_value [ , ... ] )

(,column_value)

table_elem

table_elem ::= column_name data_type [ column_constraint [ ... ] ]
               | table_constraint

column_namedata_typecolumn_constrainttable_constraint

column_constraint

column_constraint ::= [ CONSTRAINT constraint_name ]
                      { NOT NULL
                        | NULL
                        | CHECK ( expression )
                        | DEFAULT expression
                        | UNIQUE index_parameters
                        | PRIMARY KEY
                        | references_clause }
                      [ DEFERRABLE | NOT DEFERRABLE ]
                      [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]

CONSTRAINTconstraint_nameNOTNULLNULLCHECK(expression)DEFAULTexpressionUNIQUEindex_parametersPRIMARYKEYreferences_clauseDEFERRABLENOTDEFERRABLEINITIALLYDEFERREDINITIALLYIMMEDIATE

table_constraint

table_constraint ::= [ CONSTRAINT constraint_name ]
                     { CHECK ( expression )
                       | UNIQUE ( column_names ) index_parameters
                       | PRIMARY KEY ( key_columns )
                       | FOREIGN KEY ( column_names )
                         references_clause }
                     [ DEFERRABLE | NOT DEFERRABLE ]
                     [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]

CONSTRAINTconstraint_nameCHECK(expression)UNIQUE(column_names)index_parametersPRIMARYKEY(key_columns)FOREIGNKEY(column_names)references_clauseDEFERRABLENOTDEFERRABLEINITIALLYDEFERREDINITIALLYIMMEDIATE

key_columns

key_columns ::= hash_columns [ , range_columns ] | range_columns

hash_columns,range_columnsrange_columns

hash_columns

hash_columns ::= column_name [ HASH ] | ( column_name [ , ... ] ) HASH

column_nameHASH(,column_name)HASH

range_columns

range_columns ::= { column_name { ASC | DESC } } [ , ... ]

,column_nameASCDESC

references_clause

references_clause ::= REFERENCES table_name [ column_name [ , ... ] ]
                      [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ]
                      [ ON DELETE key_action ]
                      [ ON UPDATE key_action ]

REFERENCEStable_name,column_nameMATCHFULLMATCHPARTIALMATCHSIMPLEONDELETEkey_actionONUPDATEkey_action

key_action

key_action ::= NO ACTION | RESTRICT | CASCADE | SET NULL | SET DEFAULT

NOACTIONRESTRICTCASCADESETNULLSETDEFAULT

storage_parameters

storage_parameters ::= storage_parameter [ , ... ]

,storage_parameter

storage_parameter

storage_parameter ::= param_name [ = param_value ]

param_name=param_value

index_parameters

index_parameters ::= [ INCLUDE ( column_names ) ]
                     [ WITH ( storage_parameters ) ]
                     [ USING INDEX TABLESPACE tablespace_name ]

INCLUDE(column_names)WITH(storage_parameters)USINGINDEXTABLESPACEtablespace_name

create_table_as

create_table_as ::= CREATE TABLE [ IF NOT EXISTS ]  table_name
                    [ ( column_name [ , ... ] ) ]  AS query
                    [ WITH [ NO ] DATA ]

CREATETABLEIFNOTEXISTStable_name(,column_name)ASqueryWITHNODATA

create_trigger

create_trigger ::= CREATE TRIGGER name { BEFORE | AFTER | INSTEAD OF }
                   { event [ OR ... ] } ON table_name
                   [ FROM table_name ]  [ NOT DEFERRABLE ]
                   [ FOR [ EACH ] { ROW | STATEMENT } ]
                   [ WHEN ( boolean_expression ) ]  EXECUTE
                   { FUNCTION | PROCEDURE } subprogram_name (
                   [ subprogram_signature ] )

CREATETRIGGERnameBEFOREAFTERINSTEADOFOReventONtable_nameFROMtable_nameNOTDEFERRABLEFOREACHROWSTATEMENTWHEN(boolean_expression)EXECUTEFUNCTIONPROCEDUREsubprogram_name(subprogram_signature)

event

event ::= INSERT
          | UPDATE [ OF column_name [ , ... ] ]
          | DELETE
          | TRUNCATE

INSERTUPDATEOF,column_nameDELETETRUNCATE

create_composite_type

create_composite_type ::= CREATE TYPE type_name AS (
                          [ composite_type_elem [ , ... ] ] )

CREATETYPEtype_nameAS(,composite_type_elem)

create_enum_type

create_enum_type ::= CREATE TYPE type_name AS ENUM (
                     [ label [ , ... ] ] )

CREATETYPEtype_nameASENUM(,label)

create_range_type

create_range_type ::= CREATE TYPE type_name AS RANGE ( SUBTYPE =
                      subtype [ , range_type_option [ ... ] ] )

CREATETYPEtype_nameASRANGE(SUBTYPE=subtype,range_type_option)

create_base_type

create_base_type ::= CREATE TYPE type_name ( INPUT = input_function ,
                     OUTPUT = output_function
                     [ , base_type_option [ ... ] ] )

CREATETYPEtype_name(INPUT=input_function,OUTPUT=output_function,base_type_option)

create_shell_type

create_shell_type ::= CREATE TYPE type_name

CREATETYPEtype_name

composite_type_elem

composite_type_elem ::= attribute_name data_type [ COLLATE collation ]

attribute_namedata_typeCOLLATEcollation

range_type_option

range_type_option ::= SUBTYPE_OPCLASS = subtype_operator_class
                      | COLLATION = collation
                      | CANONICAL = canonical_function
                      | SUBTYPE_DIFF = subtype_diff_function

SUBTYPE_OPCLASS=subtype_operator_classCOLLATION=collationCANONICAL=canonical_functionSUBTYPE_DIFF=subtype_diff_function

base_type_option

base_type_option ::= RECEIVE = receive_function
                     | SEND = send_function
                     | TYPMOD_IN = type_modifier_input_function
                     | TYPMOD_OUT = type_modifier_output_function
                     | INTERNALLENGTH = { internallength | VARIABLE }
                     | PASSEDBYVALUE
                     | ALIGNMENT = alignment
                     | STORAGE = storage
                     | LIKE = like_type
                     | CATEGORY = category
                     | PREFERRED = preferred
                     | DEFAULT = default
                     | ELEMENT = element
                     | DELIMITER = delimiter
                     | COLLATABLE = collatable

RECEIVE=receive_functionSEND=send_functionTYPMOD_IN=type_modifier_input_functionTYPMOD_OUT=type_modifier_output_functionINTERNALLENGTH=internallengthVARIABLEPASSEDBYVALUEALIGNMENT=alignmentSTORAGE=storageLIKE=like_typeCATEGORY=categoryPREFERRED=preferredDEFAULT=defaultELEMENT=elementDELIMITER=delimiterCOLLATABLE=collatable

create_user

create_user ::= CREATE USER role_name
                [ [ WITH ] role_option [ , ... ] ]

CREATEUSERrole_nameWITH,role_option

create_user_mapping

create_user_mapping ::= CREATE USER MAPPING [ IF NOT EXISTS ] FOR user
                        SERVER server_name [ OPTIONS ( fdw_options ) ]

CREATEUSERMAPPINGIFNOTEXISTSFORuserSERVERserver_nameOPTIONS(fdw_options)

user

user ::= user_name | USER | CURRENT_USER | PUBLIC

user_nameUSERCURRENT_USERPUBLIC

create_view

create_view ::= CREATE [ OR REPLACE ] VIEW qualified_name
                [ ( name [ , ... ] ) ] AS select

CREATEORREPLACEVIEWqualified_name(,name)ASselect

deallocate

deallocate ::= DEALLOCATE [ PREPARE ] { name | ALL }

DEALLOCATEPREPAREnameALL

delete

delete ::= [ WITH [ RECURSIVE ] { common_table_expression [ , ... ] } ]
            DELETE FROM table_expr [ [ AS ] alias ]
           [ WHERE boolean_expression | WHERE CURRENT OF cursor_name ]
            [ returning_clause ]

WITHRECURSIVE,common_table_expressionDELETEFROMtable_exprASaliasWHEREboolean_expressionWHERECURRENTOFcursor_namereturning_clause

returning_clause

returning_clause ::= RETURNING { * | { output_expression
                                     [ [ AS ] output_name ] }
                                     [ , ... ] }

RETURNING*,output_expressionASoutput_name

returning_expression

returning_expression ::= output_expression [ [ AS ] output_name ]

output_expressionASoutput_name

do

do ::= DO [ LANGUAGE lang_name ] code

DOLANGUAGElang_namecode

drop_aggregate

drop_aggregate ::= DROP AGGREGATE [ IF EXISTS ]
                   { aggregate_name ( aggregate_signature ) }
                   [ , ... ] [ CASCADE | RESTRICT ]

DROPAGGREGATEIFEXISTS,aggregate_name(aggregate_signature)CASCADERESTRICT

aggregate_signature

aggregate_signature ::= * | aggregate_arg [ , ... ]
                        | [ aggregate_arg [ , ... ] ] ORDER BY
                          aggregate_arg [ , ... ]

*,aggregate_arg,aggregate_argORDERBY,aggregate_arg

drop_cast

drop_cast ::= DROP CAST [ IF EXISTS ] ( cast_signature )
              [ CASCADE | RESTRICT ]

DROPCASTIFEXISTS(cast_signature)CASCADERESTRICT

drop_database

drop_database ::= DROP DATABASE [ IF EXISTS ] database_name

DROPDATABASEIFEXISTSdatabase_name

drop_domain

drop_domain ::= DROP DOMAIN [ IF EXISTS ] name [ , ... ]
                [ CASCADE | RESTRICT ]

DROPDOMAINIFEXISTS,nameCASCADERESTRICT

drop_extension

drop_extension ::= DROP EXTENSION [ IF EXISTS ] extension_name
                   [ , ... ] [ CASCADE | RESTRICT ]

DROPEXTENSIONIFEXISTS,extension_nameCASCADERESTRICT

drop_foreign_data_wrapper

drop_foreign_data_wrapper ::= DROP FOREIGN DATA WRAPPER [ IF EXISTS ]
                              fdw_name [ CASCADE | RESTRICT ]

DROPFOREIGNDATAWRAPPERIFEXISTSfdw_nameCASCADERESTRICT

drop_foreign_table

drop_foreign_table ::= DROP FOREIGN TABLE [ IF EXISTS ] table_name
                       [ CASCADE | RESTRICT ]

DROPFOREIGNTABLEIFEXISTStable_nameCASCADERESTRICT

drop_function

drop_function ::= DROP FUNCTION [ IF EXISTS ]
                  { subprogram_name ( [ subprogram_signature ] ) }
                  [ , ... ] [ CASCADE | RESTRICT ]

DROPFUNCTIONIFEXISTS,subprogram_name(subprogram_signature)CASCADERESTRICT

drop_group

drop_group ::= DROP GROUP [ IF EXISTS ] role_name [ , ... ]

DROPGROUPIFEXISTS,role_name

drop_matview

drop_matview ::= DROP MATERIALIZED VIEW [ IF EXISTS ] matview_name
                 [ CASCADE | RESTRICT ]

DROPMATERIALIZEDVIEWIFEXISTSmatview_nameCASCADERESTRICT

drop_operator

drop_operator ::= DROP OPERATOR [ IF EXISTS ]
                  { operator_name ( operator_signature ) } [ , ... ]
                  [ CASCADE | RESTRICT ]

DROPOPERATORIFEXISTS,operator_name(operator_signature)CASCADERESTRICT

operator_signature

operator_signature ::= { left_type | NONE } , { right_type | NONE }

left_typeNONE,right_typeNONE

drop_operator_class

drop_operator_class ::= DROP OPERATOR CLASS [ IF EXISTS ]
                        operator_class_name USING index_method
                        [ CASCADE | RESTRICT ]

DROPOPERATORCLASSIFEXISTSoperator_class_nameUSINGindex_methodCASCADERESTRICT

drop_policy

drop_policy ::= DROP POLICY [ IF EXISTS ] name ON table_name
                [ CASCADE | RESTRICT ]

DROPPOLICYIFEXISTSnameONtable_nameCASCADERESTRICT

drop_procedure

drop_procedure ::= DROP PROCEDURE [ IF EXISTS ]
                   { subprogram_name ( [ subprogram_signature ] ) }
                   [ , ... ] [ CASCADE | RESTRICT ]

DROPPROCEDUREIFEXISTS,subprogram_name(subprogram_signature)CASCADERESTRICT

drop_role

drop_role ::= DROP ROLE [ IF EXISTS ] role_name [ , ... ]

DROPROLEIFEXISTS,role_name

drop_rule

drop_rule ::= DROP RULE [ IF EXISTS ] rule_name ON table_name
              [ CASCADE | RESTRICT ]

DROPRULEIFEXISTSrule_nameONtable_nameCASCADERESTRICT

drop_sequence

drop_sequence ::= DROP SEQUENCE [ IF EXISTS ] sequence_name
                  [ CASCADE | RESTRICT ]

DROPSEQUENCEIFEXISTSsequence_nameCASCADERESTRICT

drop_owned

drop_owned ::= DROP OWNED BY role_specification [ , ... ]
               [ CASCADE | RESTRICT ]

DROPOWNEDBY,role_specificationCASCADERESTRICT

drop_server

drop_server ::= DROP SERVER [ IF EXISTS ] server_name
                [ CASCADE | RESTRICT ]

DROPSERVERIFEXISTSserver_nameCASCADERESTRICT

drop_table

drop_table ::= DROP TABLE [ IF EXISTS ] table_name [ , ... ]
               [ CASCADE | RESTRICT ]

DROPTABLEIFEXISTS,table_nameCASCADERESTRICT

drop_type

drop_type ::= DROP TYPE [ IF EXISTS ] type_name [ , ... ]
              [ CASCADE | RESTRICT ]

DROPTYPEIFEXISTS,type_nameCASCADERESTRICT

drop_user

drop_user ::= DROP USER [ IF EXISTS ] role_name [ , ... ]

DROPUSERIFEXISTS,role_name

drop_trigger

drop_trigger ::= DROP TRIGGER [ IF EXISTS ] name ON table_name
                 [ CASCADE | RESTRICT ]

DROPTRIGGERIFEXISTSnameONtable_nameCASCADERESTRICT

end

end ::= END [ TRANSACTION | WORK ]

ENDTRANSACTIONWORK

execute_statement

execute_statement ::= EXECUTE name [ ( expression [ , ... ] ) ]

EXECUTEname(,expression)

explain

explain ::= EXPLAIN [ [ ANALYZE ] [ VERBOSE ] | ( option [ , ... ] ) ]
            sql_stmt

EXPLAINANALYZEVERBOSE(,option)sql_stmt

option

option ::= ANALYZE [ boolean ]
           | VERBOSE [ boolean ]
           | COSTS [ boolean ]
           | BUFFERS [ boolean ]
           | TIMING [ boolean ]
           | SUMMARY [ boolean ]
           | FORMAT { TEXT | XML | JSON | YAML }

ANALYZEbooleanVERBOSEbooleanCOSTSbooleanBUFFERSbooleanTIMINGbooleanSUMMARYbooleanFORMATTEXTXMLJSONYAML

grant_table

grant_table ::= GRANT
                { { SELECT
                    | INSERT
                    | UPDATE
                    | DELETE
                    | TRUNCATE
                    | REFERENCES
                    | TRIGGER } [ , ... ]
                  | ALL [ PRIVILEGES ] } ON
                { [ TABLE ] table_name [ , ... ]
                  | ALL TABLES IN SCHEMA schema_name [ , ... ] } TO
                grant_role_spec [ , ... ] [ WITH GRANT OPTION ]

GRANT,SELECTINSERTUPDATEDELETETRUNCATEREFERENCESTRIGGERALLPRIVILEGESONTABLE,table_nameALLTABLESINSCHEMA,schema_nameTO,grant_role_specWITHGRANTOPTION

grant_table_col

grant_table_col ::= GRANT
                    { { SELECT | INSERT | UPDATE | REFERENCES } (
                      column_names ) [ ,(column_names ... ]
                      | ALL [ PRIVILEGES ] ( column_names ) } ON
                    { [ TABLE ] table_name [ , ... ] } TO
                    grant_role_spec [ , ... ] [ WITH GRANT OPTION ]

GRANTSELECTINSERTUPDATEREFERENCES(column_names),(column_names)ALLPRIVILEGES(column_names)ONTABLE,table_nameTO,grant_role_specWITHGRANTOPTION

grant_seq

grant_seq ::= GRANT { { USAGE | SELECT | UPDATE } [ , ... ]
                      | ALL [ PRIVILEGES ] } ON
              { SEQUENCE sequence_name [ , ... ]
                | ALL SEQUENCES IN SCHEMA schema_name
                  [ , sequence_name [ ... ] ] } TO grant_role_spec
              [ , ... ] [ WITH GRANT OPTION ]

GRANT,USAGESELECTUPDATEALLPRIVILEGESONSEQUENCE,sequence_nameALLSEQUENCESINSCHEMAschema_name,sequence_nameTO,grant_role_specWITHGRANTOPTION

grant_db

grant_db ::= GRANT { { CREATE | CONNECT | TEMPORARY | TEMP } [ , ... ]
                     | ALL [ PRIVILEGES ] } ON DATABASE database_name
             [ , ... ] TO grant_role_spec [ , ... ]
             [ WITH GRANT OPTION ]

GRANT,CREATECONNECTTEMPORARYTEMPALLPRIVILEGESONDATABASE,database_nameTO,grant_role_specWITHGRANTOPTION

grant_domain

grant_domain ::= GRANT { USAGE | ALL [ PRIVILEGES ] } ON DOMAIN
                 domain_name [ , ... ] TO grant_role_spec [ , ... ]
                 [ WITH GRANT OPTION ]

GRANTUSAGEALLPRIVILEGESONDOMAIN,domain_nameTO,grant_role_specWITHGRANTOPTION

grant_schema

grant_schema ::= GRANT { { CREATE | USAGE } [ , ... ]
                         | ALL [ PRIVILEGES ] } ON SCHEMA schema_name
                 [ , ... ] TO grant_role_spec [ , ... ]
                 [ WITH GRANT OPTION ]

GRANT,CREATEUSAGEALLPRIVILEGESONSCHEMA,schema_nameTO,grant_role_specWITHGRANTOPTION

grant_type

grant_type ::= GRANT { USAGE | ALL [ PRIVILEGES ] } ON TYPE type_name
               [ , ... ] TO grant_role_spec [ , ... ]
               [ WITH GRANT OPTION ]

GRANTUSAGEALLPRIVILEGESONTYPE,type_nameTO,grant_role_specWITHGRANTOPTION

grant_role

grant_role ::= GRANT role_name [ , ... ] TO role_name [ , ... ]
               [ WITH ADMIN OPTION ]

GRANT,role_nameTO,role_nameWITHADMINOPTION

grant_role_spec

grant_role_spec ::= [ GROUP ] role_name
                    | PUBLIC
                    | CURRENT_USER
                    | SESSION_USER

GROUProle_namePUBLICCURRENT_USERSESSION_USER

import_foreign_schema

import_foreign_schema ::= IMPORT FOREIGN SCHEMA remote_schema
                          [ { LIMIT TO | EXCEPT } ( table_name [ ... ]
                            ) ] FROM SERVER server_name INTO
                          local_schema [ OPTIONS ( fdw_options ) ]

IMPORTFOREIGNSCHEMAremote_schemaLIMITTOEXCEPT(table_name)FROMSERVERserver_nameINTOlocal_schemaOPTIONS(fdw_options)

remote_schema

remote_schema ::= '<Text Literal>'

<Text Literal>

local_schema

local_schema ::= '<Text Literal>'

<Text Literal>

insert

insert ::= [ WITH [ RECURSIVE ] { common_table_expression [ , ... ] } ]
            INSERT INTO table_name [ AS alias ] [ ( column_names ) ]
           { DEFAULT VALUES
             | VALUES ( column_values ) [ ,(column_values ... ]
             | subquery }
           [ ON CONFLICT [ conflict_target ] conflict_action ]
           [ returning_clause ]

WITHRECURSIVE,common_table_expressionINSERTINTOtable_nameASalias(column_names)DEFAULTVALUESVALUES(column_values),(column_values)subqueryONCONFLICTconflict_targetconflict_actionreturning_clause

column_values

column_values ::= { expression | DEFAULT } [ , ... ]

,expressionDEFAULT

conflict_target

conflict_target ::= ( { column_name | expression } [ , ... ] )
                    [ WHERE boolean_expression ]
                    | ON CONSTRAINT constraint_name

(,column_nameexpression)WHEREboolean_expressionONCONSTRAINTconstraint_name

conflict_action

conflict_action ::= DO NOTHING
                    | DO UPDATE SET update_item [ , ... ]
                      [ WHERE boolean_expression ]

DONOTHINGDOUPDATESET,update_itemWHEREboolean_expression

lock_table

lock_table ::= LOCK [ TABLE ] { table_expr [ , ... ] }
               [ IN lockmode MODE ] [ NOWAIT ]

LOCKTABLE,table_exprINlockmodeMODENOWAIT

lockmode

lockmode ::= ACCESS SHARE
             | ROW SHARE
             | ROW EXCLUSIVE
             | SHARE UPDATE EXCLUSIVE
             | SHARE
             | SHARE ROW EXCLUSIVE
             | EXCLUSIVE
             | ACCESS EXCLUSIVE

ACCESSSHAREROWSHAREROWEXCLUSIVESHAREUPDATEEXCLUSIVESHARESHAREROWEXCLUSIVEEXCLUSIVEACCESSEXCLUSIVE

prepare_statement

prepare_statement ::= PREPARE name [ ( data_type [ , ... ] ) ] AS
                      sql_stmt

PREPAREname(,data_type)ASsql_stmt

reassign_owned

reassign_owned ::= REASSIGN OWNED BY role_specification [ , ... ] TO
                   role_specification

REASSIGNOWNEDBY,role_specificationTOrole_specification

refresh_matview

refresh_matview ::= REFRESH MATERIALIZED VIEW [ CONCURRENTLY ]
                    matview_name [ WITH [ NO ] DATA ]

REFRESHMATERIALIZEDVIEWCONCURRENTLYmatview_nameWITHNODATA

reset_stmt

reset_stmt ::= RESET { name | ALL }

RESETnameALL

reset_role

reset_role ::= RESET ROLE

RESETROLE

reset_session_authorization

reset_session_authorization ::= RESET SESSION AUTHORIZATION

RESETSESSIONAUTHORIZATION

revoke_table

revoke_table ::= REVOKE [ GRANT OPTION FOR ]
                 { { SELECT
                     | INSERT
                     | UPDATE
                     | DELETE
                     | TRUNCATE
                     | REFERENCES
                     | TRIGGER } [ , ... ]
                   | ALL [ PRIVILEGES ] } ON
                 { [ TABLE ] table_name [ , ... ]
                   | ALL TABLES IN SCHEMA schema_name [ , ... ] } FROM
                 { [ GROUP ] role_name | PUBLIC } [ , ... ]
                 [ CASCADE | RESTRICT ]

REVOKEGRANTOPTIONFOR,SELECTINSERTUPDATEDELETETRUNCATEREFERENCESTRIGGERALLPRIVILEGESONTABLE,table_nameALLTABLESINSCHEMA,schema_nameFROM,GROUProle_namePUBLICCASCADERESTRICT

revoke_table_col

revoke_table_col ::= REVOKE [ GRANT OPTION FOR ]
                     { { SELECT | INSERT | UPDATE | REFERENCES } (
                       column_names ) [ ,(column_names ... ]
                       | ALL [ PRIVILEGES ] ( column_names ) } ON
                     [ TABLE ] table_name [ , ... ] FROM
                     { [ GROUP ] role_name | PUBLIC } [ , ... ]
                     [ CASCADE | RESTRICT ]

REVOKEGRANTOPTIONFORSELECTINSERTUPDATEREFERENCES(column_names),(column_names)ALLPRIVILEGES(column_names)ONTABLE,table_nameFROM,GROUProle_namePUBLICCASCADERESTRICT

revoke_seq

revoke_seq ::= REVOKE [ GRANT OPTION FOR ]
               { { USAGE | SELECT | UPDATE } [ , ... ]
                 | ALL [ PRIVILEGES ] } ON
               { SEQUENCE sequence_name [ , ... ]
                 | ALL SEQUENCES IN SCHEMA schema_name [ , ... ] }
               FROM { [ GROUP ] role_name | PUBLIC } [ , ... ]
               [ CASCADE | RESTRICT ]

REVOKEGRANTOPTIONFOR,USAGESELECTUPDATEALLPRIVILEGESONSEQUENCE,sequence_nameALLSEQUENCESINSCHEMA,schema_nameFROM,GROUProle_namePUBLICCASCADERESTRICT

revoke_db

revoke_db ::= REVOKE [ GRANT OPTION FOR ]
              { { CREATE | CONNECT | TEMPORARY | TEMP } [ , ... ]
                | ALL [ PRIVILEGES ] } ON DATABASE database_name
              [ , ... ] FROM { [ GROUP ] role_name | PUBLIC }
              [ , ... ] [ CASCADE | RESTRICT ]

REVOKEGRANTOPTIONFOR,CREATECONNECTTEMPORARYTEMPALLPRIVILEGESONDATABASE,database_nameFROM,GROUProle_namePUBLICCASCADERESTRICT

revoke_domain

revoke_domain ::= REVOKE [ GRANT OPTION FOR ]
                  { USAGE | ALL [ PRIVILEGES ] } ON DOMAIN domain_name
                  [ , ... ] FROM { [ GROUP ] role_name | PUBLIC }
                  [ , ... ] [ CASCADE | RESTRICT ]

REVOKEGRANTOPTIONFORUSAGEALLPRIVILEGESONDOMAIN,domain_nameFROM,GROUProle_namePUBLICCASCADERESTRICT

revoke_schema

revoke_schema ::= REVOKE [ GRANT OPTION FOR ]
                  { { CREATE | USAGE } [ , ... ]
                    | ALL [ PRIVILEGES ] } ON SCHEMA schema_name
                  [ , ... ] FROM { [ GROUP ] role_name | PUBLIC }
                  [ , ... ] [ CASCADE | RESTRICT ]

REVOKEGRANTOPTIONFOR,CREATEUSAGEALLPRIVILEGESONSCHEMA,schema_nameFROM,GROUProle_namePUBLICCASCADERESTRICT

revoke_type

revoke_type ::= REVOKE [ GRANT OPTION FOR ]
                { USAGE | ALL [ PRIVILEGES ] } ON TYPE type_name
                [ , ... ] FROM { [ GROUP ] role_name | PUBLIC }
                [ , ... ] [ CASCADE | RESTRICT ]

REVOKEGRANTOPTIONFORUSAGEALLPRIVILEGESONTYPE,type_nameFROM,GROUProle_namePUBLICCASCADERESTRICT

revoke_role

revoke_role ::= REVOKE [ ADMIN OPTION FOR ] role_name [ , ... ] FROM
                role_name [ , ... ] [ CASCADE | RESTRICT ]

REVOKEADMINOPTIONFOR,role_nameFROM,role_nameCASCADERESTRICT

rollback

rollback ::= ROLLBACK [ TRANSACTION | WORK ]

ROLLBACKTRANSACTIONWORK

select

select ::= [ WITH [ RECURSIVE ] { common_table_expression [ , ... ] } ]
            SELECT [ ALL |
                     DISTINCT [ ON { ( expression [ , ... ] ) } ] ]
           [ * | { { expression
                     | fn_over_window
                     | ordinary_aggregate_fn_invocation
                     | within_group_aggregate_fn_invocation }
                 [ [ AS ] name ] } [ , ... ] ]
           [ FROM { from_item [ , ... ] } ]
           [ WHERE boolean_expression ]
           [ GROUP BY { grouping_element [ , ... ] } ]
           [ HAVING boolean_expression ]
           [ WINDOW { { name AS window_definition } [ , ... ] } ]
           [ { UNION | INTERSECT | EXCEPT } [ ALL | DISTINCT ] select ]
            [ ORDER BY { order_expr [ , ... ] } ]
           [ LIMIT { integer | ALL } ]
           [ OFFSET integer [ ROW | ROWS ] ]
           [ FETCH { FIRST | NEXT } integer { ROW | ROWS } ONLY ]
           [ FOR { UPDATE | NO KEY UPDATE | SHARE | KEY SHARE }
             [ OF table_name [ , ... ] ] [ NOWAIT | SKIP LOCKED ] [ ... ] ]

WITHRECURSIVE,common_table_expressionSELECTALLDISTINCTON(,expression)*,expressionfn_over_windowordinary_aggregate_fn_invocationwithin_group_aggregate_fn_invocationASnameFROM,from_itemWHEREboolean_expressionGROUPBY