PostgreSQL - Sintaxis

Este capítulo proporciona una lista de los comandos SQL de PostgreSQL, seguida de las reglas de sintaxis precisas para cada uno de estos comandos. Este conjunto de comandos se toma de la herramienta de línea de comandos psql. Ahora que tiene Postgres instalado, abra psql como:

Program Files → PostgreSQL 9.2 → SQL Shell(psql).

Con psql, puede generar una lista completa de comandos mediante el comando \ help. Para la sintaxis de un comando específico, use el siguiente comando:

postgres-# \help <command_name>

La declaración SQL

Una declaración SQL se compone de tokens donde cada token puede representar una palabra clave, identificador, identificador entre comillas, constante o símbolo de carácter especial. La tabla que se proporciona a continuación utiliza una instrucción SELECT simple para ilustrar una instrucción SQL básica, pero completa, y sus componentes.

SELECCIONE id, nombre DESDE estados
Tipo de token Palabra clave Identificadores Palabra clave Identificador
Descripción Mando Columnas de identificación y nombre Cláusula Nombre de la tabla

Comandos SQL de PostgreSQL

ABORTAR

Abortar la transacción actual.

ABORT [ WORK | TRANSACTION ]

ALTERAR AGREGAR

Cambie la definición de una función agregada.

ALTER AGGREGATE name ( type ) RENAME TO new_name
ALTER AGGREGATE name ( type ) OWNER TO new_owner

ALTERAR LA CONVERSIÓN

Cambia la definición de conversión.

ALTER CONVERSION name RENAME TO new_name
ALTER CONVERSION name OWNER TO new_owner

ALTERAR BASE DE DATOS

Cambiar un parámetro específico de la base de datos.

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

Cambie la definición de un parámetro específico de dominio.

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

FUNCIÓN ALTER

Cambia la definición de una función.

ALTER FUNCTION name ( [ type [, ...] ] ) RENAME TO new_name
ALTER FUNCTION name ( [ type [, ...] ] ) OWNER TO new_owner

ALTERAR GRUPO

Cambiar un grupo de usuarios.

ALTER GROUP groupname ADD USER username [, ... ]
ALTER GROUP groupname DROP USER username [, ... ]
ALTER GROUP groupname RENAME TO new_name

ALTER INDICE

Cambia la definición de un índice.

ALTER INDEX name OWNER TO new_owner
ALTER INDEX name SET TABLESPACE indexspace_name
ALTER INDEX name RENAME TO new_name

ALTERAR IDIOMA

Cambie la definición de un lenguaje procedimental.

ALTER LANGUAGE name RENAME TO new_name

OPERADOR ALTER

Cambie la definición de un operador.

ALTER OPERATOR name ( { lefttype | NONE }, { righttype | NONE } )
OWNER TO new_owner

CLASE DE OPERADOR ALTER

Cambie la definición de una clase de operador.

ALTER OPERATOR CLASS name USING index_method RENAME TO new_name
ALTER OPERATOR CLASS name USING index_method OWNER TO new_owner

ALTER SCHEMA

Cambia la definición de un esquema.

ALTER SCHEMA name RENAME TO new_name
ALTER SCHEMA name OWNER TO new_owner

ALTER SEQUENCE

Cambia la definición de un generador de secuencias.

ALTER SEQUENCE name [ INCREMENT [ BY ] increment ]
[ MINVALUE minvalue | NO MINVALUE ]
[ MAXVALUE maxvalue | NO MAXVALUE ]
[ RESTART [ WITH ] start ] [ CACHE cache ] [ [ NO ] CYCLE ]

ALTERAR TABLA

Cambia la definición de una tabla.

ALTER TABLE [ ONLY ] name [ * ]
action [, ... ]
ALTER TABLE [ ONLY ] name [ * ]
RENAME [ COLUMN ] column TO new_column
ALTER TABLE name
RENAME TO new_name

Donde la acción es una de las siguientes líneas:

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

ALTER TABLESPACE

Cambie la definición de un espacio de tabla.

ALTER TABLESPACE name RENAME TO new_name
ALTER TABLESPACE name OWNER TO new_owner

ALTER TRIGGER

Cambia la definición de un disparador.

ALTER TRIGGER name ON table RENAME TO new_name

ALTER TIPO

Cambie la definición de un tipo.

ALTER TYPE name OWNER TO new_owner

ALTER USUARIO

Cambiar una cuenta de usuario de la base de datos.

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

Donde la opción puede ser -

[ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password'
| CREATEDB | NOCREATEDB
| CREATEUSER | NOCREATEUSER
| VALID UNTIL 'abstime'

ANALIZAR

Recopile estadísticas sobre una base de datos.

ANALYZE [ VERBOSE ] [ table [ (column [, ...] ) ] ]

EMPEZAR

Inicie un bloque de transacciones.

BEGIN [ WORK | TRANSACTION ] [ transaction_mode [, ...] ]

Donde transaction_mode es uno de:

ISOLATION LEVEL { 
   SERIALIZABLE | REPEATABLE READ | READ COMMITTED
   | READ UNCOMMITTED
}
READ WRITE | READ ONLY

CONTROL

Forzar un punto de control del registro de transacciones.

CHECKPOINT

CERCA

Cierre un cursor.

CLOSE name

RACIMO

Agrupe una tabla según un índice.

CLUSTER index_name ON table_name
CLUSTER table_name
CLUSTER

COMENTARIO

Definir o cambiar el comentario de un objeto.

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'

COMETER

Confirma la transacción actual.

COMMIT [ WORK | TRANSACTION ]

COPIAR

Copie datos entre un archivo y una tabla.

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 [, ...] ]

CREAR AGREGADO

Defina una nueva función agregada.

CREATE AGGREGATE name (
   BASETYPE = input_data_type,
   SFUNC = sfunc,
   STYPE = state_data_type
   [, FINALFUNC = ffunc ]
   [, INITCOND = initial_condition ]
)

CREAR REPARTO

Defina un nuevo elenco.

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 ]

CREAR DISPARADOR DE RESTRICCIONES

Defina un nuevo activador de restricción.

CREATE CONSTRAINT TRIGGER name
AFTER events ON
table_name constraint attributes
FOR EACH ROW EXECUTE PROCEDURE func_name ( args )

CREAR CONVERSIÓN

Defina una nueva conversión.

CREATE [DEFAULT] CONVERSION name
FOR source_encoding TO dest_encoding FROM func_name

CREAR BASE DE DATOS

Crea una nueva base de datos.

CREATE DATABASE name
[ [ WITH ] [ OWNER [=] db_owner ]
   [ TEMPLATE [=] template ]
   [ ENCODING [=] encoding ]
   [ TABLESPACE [=] tablespace ] 
]

CREAR DOMINIO

Defina un nuevo dominio.

CREATE DOMAIN name [AS] data_type
[ DEFAULT expression ]
[ constraint [ ... ] ]

Donde la restricción es -

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

CREAR FUNCIÓN

Defina una nueva función.

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 [, ...] ) ]

CREA UN GRUPO

Defina un nuevo grupo de usuarios.

CREATE GROUP name [ [ WITH ] option [ ... ] ]
Where option can be:
SYSID gid
| USER username [, ...]

CREAR ÍNDICE

Defina un nuevo índice.

CREATE [ UNIQUE ] INDEX name ON table [ USING method ]
( { column | ( expression ) } [ opclass ] [, ...] )
[ TABLESPACE tablespace ]
[ WHERE predicate ]

CREAR IDIOMA

Definir un nuevo lenguaje procedimental.

CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE name
HANDLER call_handler [ VALIDATOR val_function ]

CREAR OPERADOR

Defina un nuevo operador.

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 ]
)

CREAR CLASE DE OPERADOR

Defina una nueva clase de operador.

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
} [, ... ]

CREAR REGLA

Defina una nueva regla de reescritura.

CREATE [ OR REPLACE ] RULE name AS ON event
TO table [ WHERE condition ]
DO [ ALSO | INSTEAD ] { NOTHING | command | ( command ; command ... ) }

CREAR ESQUEMA

Defina un nuevo esquema.

CREATE SCHEMA schema_name
[ AUTHORIZATION username ] [ schema_element [ ... ] ]
CREATE SCHEMA AUTHORIZATION username
[ schema_element [ ... ] ]

CREAR SECUENCIA

Defina un nuevo generador de secuencias.

CREATE [ TEMPORARY | TEMP ] SEQUENCE name
[ INCREMENT [ BY ] increment ]
[ MINVALUE minvalue | NO MINVALUE ]
[ MAXVALUE maxvalue | NO MAXVALUE ]
[ START [ WITH ] start ] [ CACHE cache ] [ [ NO ] CYCLE ]

CREAR MESA

Defina una nueva tabla.

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 ]

Donde column_constraint es -

[ 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 ]

Y table_constraint es -

[ 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 ]

CREAR TABLA COMO

Defina una nueva tabla a partir de los resultados de una consulta.

CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name
[ (column_name [, ...] ) ] [ [ WITH | WITHOUT ] OIDS ]
AS query

CREAR TABLESPACE

Defina un nuevo espacio de tabla.

CREATE TABLESPACE tablespace_name [ OWNER username ] LOCATION 'directory'

CREAR DISPARADOR

Defina un nuevo disparador.

CREATE TRIGGER name { BEFORE | AFTER } { event [ OR ... ] }
ON table [ FOR [ EACH ] { ROW | STATEMENT } ]
EXECUTE PROCEDURE func_name ( arguments )

CREAR TIPO

Defina un nuevo tipo de datos.

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 ]
)

CREAR USUARIO

Defina una nueva cuenta de usuario de base de datos.

CREATE USER name [ [ WITH ] option [ ... ] ]

Donde la opción puede ser -

SYSID uid
| [ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password'
| CREATEDB | NOCREATEDB
| CREATEUSER | NOCREATEUSER
| IN GROUP group_name [, ...]
| VALID UNTIL 'abs_time'

CREAR VISTA

Defina una nueva vista.

CREATE [ OR REPLACE ] VIEW name [ ( column_name [, ...] ) ] AS query

DESACTIVAR

Desasignar una declaración preparada.

DEALLOCATE [ PREPARE ] plan_name

DECLARAR

Defina un cursor.

DECLARE name [ BINARY ] [ INSENSITIVE ] [ [ NO ] SCROLL ]
CURSOR [ { WITH | WITHOUT } HOLD ] FOR query
[ FOR { READ ONLY | UPDATE [ OF column [, ...] ] } ]

ELIMINAR

Elimina filas de una tabla.

DELETE FROM [ ONLY ] table [ WHERE condition ]

AGREGADO DE GOTA

Eliminar una función agregada.

DROP AGGREGATE name ( type ) [ CASCADE | RESTRICT ]

Lanzamiento de gota

Retire un yeso.

DROP CAST (source_type AS target_type) [ CASCADE | RESTRICT ]

CONVERSIÓN DE GOTA

Eliminar una conversión.

DROP CONVERSION name [ CASCADE | RESTRICT ]

DROP DATABASE

Eliminar una base de datos.

DROP DATABASE name

DROP DOMAIN

Eliminar un dominio.

DROP DOMAIN name [, ...] [ CASCADE | RESTRICT ]

FUNCIÓN DROP

Eliminar una función.

DROP FUNCTION name ( [ type [, ...] ] ) [ CASCADE | RESTRICT ]

GRUPO DE GOTA

Eliminar un grupo de usuarios.

DROP GROUP name

ÍNDICE DE GOTA

Eliminar un índice.

DROP INDEX name [, ...] [ CASCADE | RESTRICT ]

LENGUAJE DROP

Eliminar un lenguaje de procedimiento.

DROP [ PROCEDURAL ] LANGUAGE name [ CASCADE | RESTRICT ]

OPERADOR DE GOTA

Eliminar un operador.

DROP OPERATOR name ( { left_type | NONE }, { right_type | NONE } )
[ CASCADE | RESTRICT ]

CLASE DE OPERADOR DE GOTAS

Eliminar una clase de operador.

DROP OPERATOR CLASS name USING index_method [ CASCADE | RESTRICT ]

REGLA DE GOTA

Elimina una regla de reescritura.

DROP RULE name ON relation [ CASCADE | RESTRICT ]

ESQUEMA DE GOTA

Eliminar un esquema.

DROP SCHEMA name [, ...] [ CASCADE | RESTRICT ]

SECUENCIA DE GOTA

Eliminar una secuencia.

DROP SEQUENCE name [, ...] [ CASCADE | RESTRICT ]

MESA PLEGABLE

Retire una mesa.

DROP TABLE name [, ...] [ CASCADE | RESTRICT ]

ESPACIO DE MESA DE GOTA

Eliminar un espacio de tabla.

DROP TABLESPACE tablespace_name

GATILLO DE GOTA

Retire un gatillo.

DROP TRIGGER name ON table [ CASCADE | RESTRICT ]

TIPO DE GOTA

Eliminar un tipo de datos.

DROP TYPE name [, ...] [ CASCADE | RESTRICT ]

DROP USER

Eliminar una cuenta de usuario de la base de datos.

DROP USER name

VISTA GOTA

Eliminar una vista.

DROP VIEW name [, ...] [ CASCADE | RESTRICT ]

FIN

Confirma la transacción actual.

END [ WORK | TRANSACTION ]

EJECUTAR

Ejecute una declaración preparada.

EXECUTE plan_name [ (parameter [, ...] ) ]

EXPLIQUE

Muestre el plan de ejecución de una declaración.

EXPLAIN [ ANALYZE ] [ VERBOSE ] statement

IR A BUSCAR

Recupere filas de una consulta usando un cursor.

FETCH [ direction { FROM | IN } ] cursor_name

Donde la dirección puede estar vacía o una de las siguientes:

NEXT
PRIOR
FIRST
LAST
ABSOLUTE count
RELATIVE count
count
ALL
FORWARD
FORWARD count
FORWARD ALL
BACKWARD
BACKWARD count
BACKWARD ALL

CONCEDER

Defina privilegios de acceso.

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 ]

INSERTAR

Crea nuevas filas en una tabla.

INSERT INTO table [ ( column [, ...] ) ]
{ DEFAULT VALUES | VALUES ( { expression | DEFAULT } [, ...] ) | query }

ESCUCHA

Escuche una notificación.

LISTEN name

CARGA

Cargue o vuelva a cargar un archivo de biblioteca compartida.

LOAD 'filename'

BLOQUEAR

Bloquea una mesa.

LOCK [ TABLE ] name [, ...] [ IN lock_mode MODE ] [ NOWAIT ]

Donde lock_mode es uno de -

ACCESS SHARE | ROW SHARE | ROW EXCLUSIVE | SHARE UPDATE EXCLUSIVE
| SHARE | SHARE ROW EXCLUSIVE | EXCLUSIVE | ACCESS EXCLUSIVE

MOVERSE

Coloque un cursor.

MOVE [ direction { FROM | IN } ] cursor_name

NOTIFICAR

Genera una notificación.

NOTIFY name

PREPARAR

Prepare una declaración para su ejecución.

PREPARE plan_name [ (data_type [, ...] ) ] AS statement

REINDEX

Reconstruir índices.

REINDEX { DATABASE | TABLE | INDEX } name [ FORCE ]

LIBERAR SAVEPOINT

Destruye un punto de guardado previamente definido.

RELEASE [ SAVEPOINT ] savepoint_name

REINICIAR

Restaura el valor de un parámetro de tiempo de ejecución al valor predeterminado.

RESET name
RESET ALL

REVOCAR

Quite los privilegios de acceso.

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 ]

RETROCEDER

Abortar la transacción actual.

ROLLBACK [ WORK | TRANSACTION ]

ROLLBACK TO SAVEPOINT

Regrese a un punto de guardado.

ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] savepoint_name

PUNTO DE GUARDADO

Defina un nuevo punto de guardado dentro de la transacción actual.

SAVEPOINT savepoint_name

SELECCIONE

Recupere filas de una tabla o vista.

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 [, ...] ] ]
Donde from_item puede ser uno de:
[ 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 [, ...] ) ]

SELECCIONAR EN

Defina una nueva tabla a partir de los resultados de una consulta.

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 [, ...] ] ]

CONJUNTO

Cambiar un parámetro de tiempo de ejecución.

SET [ SESSION | LOCAL ] name { TO | = } { value | 'value' | DEFAULT }
SET [ SESSION | LOCAL ] TIME ZONE { time_zone | LOCAL | DEFAULT }

ESTABLECER RESTRICCIONES

Establecer modos de comprobación de restricciones para la transacción actual.

SET CONSTRAINTS { ALL | name [, ...] } { DEFERRED | IMMEDIATE }

CONFIGURAR AUTORIZACIÓN DE SESIÓN

Establezca el identificador de usuario de la sesión y el identificador de usuario actual de la sesión actual.

SET [ SESSION | LOCAL ] SESSION AUTHORIZATION username
SET [ SESSION | LOCAL ] SESSION AUTHORIZATION DEFAULT
RESET SESSION AUTHORIZATION

CONFIGURAR TRANSACCIÓN

Establece las características de la transacción actual.

SET TRANSACTION transaction_mode [, ...]
SET SESSION CHARACTERISTICS AS TRANSACTION transaction_mode [, ...]

Donde transaction_mode es uno de:

ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED
| READ UNCOMMITTED }
READ WRITE | READ ONLY

SHOW

Muestra el valor de un parámetro de tiempo de ejecución.

SHOW name
SHOW ALL

INICIAR TRANSACCIÓN

Inicie un bloque de transacciones.

START TRANSACTION [ transaction_mode [, ...] ]

Donde transaction_mode es uno de:

ISOLATION LEVEL { SERIALIZABLE | REPEATABLE READ | READ COMMITTED
| READ UNCOMMITTED }
READ WRITE | READ ONLY

TRUNCAR

Vacíe una mesa.

TRUNCATE [ TABLE ] name

NO ESCUCHAR

Deja de escuchar una notificación.

UNLISTEN { name | * }

ACTUALIZAR

Actualiza filas de una tabla.

UPDATE [ ONLY ] table SET column = { expression | DEFAULT } [, ...]
[ FROM from_list ]
[ WHERE condition ]

VACÍO

Recolectar basura y, opcionalmente, analizar una base de datos.

VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ table ]
VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] ANALYZE [ table [ (column [, ...] ) ] ]