Back to Yugabyte Db

SQL statements [YSQL]

docs/content/v2025.1/api/ysql/the-sql-language/statements/_index.md

2026.1.0.0-b298.6 KB
Original Source

The YSQL statements are compatible with the SQL dialect that PostgreSQL supports. The sidebar lists all of the YSQL statements in alphabetical order. The following tables list them by category.

Data definition language (DDL)

StatementDescription
ALTER DATABASEChange database definition
ALTER DOMAINChange domain definition
ALTER FOREIGN DATA WRAPPERChange foreign data wrapper definition
ALTER FOREIGN TABLEChange foreign table definition
ALTER INDEXChange index definition
ALTER MATERIALIZED VIEWChange materialized view definition
ALTER PUBLICATIONChange publication definition
ALTER SEQUENCEChange sequence definition
ALTER SERVERChange foreign server definition
ALTER SCHEMAChange schema definition
ALTER TABLEChange table definition
COMMENTSet, update, or remove a comment on a database object
CREATE AGGREGATECreate an aggregate
CREATE CASTCreate a cast
CREATE DATABASECreate a database
CREATE DOMAINCreate a user-defined data type with optional constraints
CREATE EXTENSIONLoad an extension
CREATE FOREIGN DATA WRAPPERCreate a foreign-data wrapper
CREATE FOREIGN TABLECreate a foreign table
CREATE FUNCTIONCreate a function
CREATE INDEXCreate an index
CREATE MATERIALIZED VIEWCreate a materialized view
CREATE OPERATORCreate an operator
CREATE OPERATOR CLASSCreate an operator class
CREATE PROCEDURECreate a procedure
CREATE PUBLICATIONCreate a publication
CREATE RULECreate a rule
CREATE SCHEMACreate a schema (namespace)
CREATE SEQUENCECreate a sequence generator
CREATE SERVERCreate a foreign server
CREATE TABLECreate an empty table
CREATE TABLE ASCreate a table from the results of a executing a SELECT
CREATE TABLESPACECreate a tablespace
CREATE TRIGGERCreate a trigger
CREATE TYPECreate a type
CREATE USER MAPPINGCreate a user mapping
CREATE VIEWCreate a view
DROP AGGREGATEDelete an aggregate
DROP CASTDelete a cast
DROP DATABASEDelete a database from the system
DROP DOMAINDelete a domain
DROP EXTENSIONDelete an extension
DROP FOREIGN DATA WRAPPERDrop a foreign-data wrapper
DROP FOREIGN TABLEDrop a foreign table
DROP FUNCTIONDelete a function
DROP INDEXDelete an index from a database
DROP MATERIALIZED VIEWDrop a materialized view
DROP OPERATORDelete an operator
DROP OPERATOR CLASSDelete an operator class
DROP PROCEDUREDelete a procedure
DROP PUBLICATIONDelete a publication
DROP RULEDelete a rule
DROP SCHEMADelete a schema from the system
DROP SEQUENCEDelete a sequence generator
DROP SERVERDrop a foreign server
DROP TABLEDelete a table from a database
DROP TABLESPACEDelete a tablespace from the cluster
DROP TYPEDelete a user-defined type
DROP TRIGGERDelete a trigger
DROP VIEWDrop a view
IMPORT FOREIGN SCHEMAImport a foreign schema
REFRESH MATERIALIZED VIEWRefresh a materialized view
TRUNCATEClear all rows from a table

Data manipulation language (DML)

StatementDescription
CLOSERemove a cursor
DECLARECreate a cursor
DELETEDelete rows from a table
FETCHFetch rows from a cursor
INSERTInsert rows into a table
MOVEMove the current position within a cursor
SELECTSelect rows from a table
UPDATEUpdate rows in a table

Data control language (DCL)

StatementDescription
ALTER DEFAULT PRIVILEGESDefine default privileges
ALTER GROUPAlter a group
ALTER POLICYAlter a row level security policy
ALTER ROLEAlter a role (user or group)
ALTER USERAlter a user
CREATE GROUPCreate a group (role)
CREATE POLICYCreate a row level security policy
CREATE ROLECreate a role (user or group)
CREATE USERCreate a user (role)
DROP GROUPDrop a group
DROP POLICYDrop a row level security policy
DROP ROLEDrop a role (user or group)
DROP OWNEDDrop owned objects
DROP USERDrop a user
GRANTGrant permissions
REASSIGN OWNEDReassign owned objects
REVOKERevoke permissions
SET ROLESet a role
SET SESSION AUTHORIZATIONSet session authorization

Transaction control language (TCL)

StatementDescription
ABORTRoll back a transaction
BEGINStart a transaction
COMMITCommit a transaction
ENDCommit a transaction
LOCKLock a table
ROLLBACKRoll back a transaction
SET CONSTRAINTSSet constraints on current transaction
SET TRANSACTIONSet transaction behaviors
SHOW TRANSACTIONShow properties of a transaction
START TRANSACTIONStart a transaction
SAVEPOINTCreate a new savepoint
ROLLBACK TORollback to a savepoint
RELEASERelease a savepoint

Session and system control

StatementDescription
RESETReset a run-time parameter to its default value
SETSet the value of a run-time parameter
SHOWShow the value of a run-time parameter

Performance control

StatementDescription
DEALLOCATEDeallocate a prepared statement
EXECUTEExecute a prepared statement
EXPLAINExplain an execution plan for a statement
PREPAREPrepare a statement

Streaming replication protocol statements

StatementDescription
CREATE_REPLICATION_SLOTCreate a replication slot
DROP_REPLICATION_SLOTDrop a replication slot
START_REPLICATIONStart streaming from a replication slot

Other statements

StatementDescription
ANALYZECollect statistics about a database
COPYCopy data between tables and files
DOExecute an anonymous PL/pgSQL code block