PostgreSQL Reference

Last updated: 2026-11-04

PostgreSQL Reference

Alphabetical list of 120 PostgreSQL items with syntax, parameters, and runnable examples.

#
+The addition operator + sums two numeric operands and is the most basic arithmetic operati...
-The subtraction operator - subtracts the right operand from the left, and also acts as a u...
*The multiplication operator * multiplies two numeric operands and is the usual way to comp...
/The division operator / behaves differently depending on operand types: integer divided by...
%The modulo operator % returns the remainder of integer division and is equivalent to the m...
^The exponentiation operator ^ raises the left operand to the power of the right operand an...
=The equality operator = compares two operands for equality and is the most common filter i...
<>The inequality operator <> reports whether two operands differ; PostgreSQL also accepts !=...
<The less-than operator < reports whether the left operand is smaller than the right, and w...
>The greater-than operator > reports whether the left operand is larger than the right and ...
|||| joins two values into a single text result and is the only string concatenation operato...
->-> extracts a sub-value from jsonb by key or array index and returns jsonb itself, so call...
->>->> differs from -> in exactly one way, and it matters: ->> returns text instead of jsonb....
@>@> reports whether the left jsonb contains the right jsonb. Containment is recursive and s...
表达式索引An expression index stores the result of an expression over a column rather than the colum...
部分索引A partial index stores only the rows that satisfy its WHERE predicate, which makes it far ...
覆盖索引(INCLUDE)A covering index adds extra read-only reference columns via INCLUDE. They do not participa...
唯一索引CREATE UNIQUE INDEX enforces uniqueness on the indexed columns while building the index. I...
多列索引(复合索引)A composite index combines several columns into one key in the order given, so it can serv...
A
abs(numeric)abs() returns the absolute value of a number, turning negatives positive and leaving every...
ANDAND joins two boolean conditions and yields true only when both sides are true. It follows...
ALTER TABLEALTER TABLE changes the shape of an existing table: adding or dropping columns, changing c...
ALTER SEQUENCEALTER SEQUENCE retunes an existing sequence: changing its step, bounds, or cache, restarti...
ANALYZEANALYZE scans a table and updates the statistics the planner relies on: row counts, the di...
ADD CONSTRAINT ... NOT VALID / VALIDATE CONSTRAINTAdding a CHECK or foreign key to a large existing table means a full scan and a lock, whic...
B
BIGINTBIGINT (INT8) occupies 8 bytes with a range of -9223372036854775808 to 9223372036854775807...
BIGSERIALBIGSERIAL stands to SERIAL as BIGINT stands to INTEGER: it is a pseudo-type made of a BIGI...
B-treeB-tree is PostgreSQL's default index type. It stores entries in a balanced tree, keeping k...
BRINBRIN (Block Range INdex) stores no per-row keys. It groups the table into ranges of pages ...
btree_gistGiST natively covers only a handful of types — geometries and ranges — so plain int or tex...
C
CHARCHAR(n) is the fixed-length character type: the value is stored padded to n characters, an...
concat(...any)concat() converts any number of values to text and joins them, silently skipping NULL argu...
ceil(numeric)ceil() rounds a value up to the nearest integer; ceiling() is an alias and floor() rounds ...
coalesce(anycompatible, ...)coalesce() returns the first non-NULL argument from left to right, or NULL if they are all...
CREATE TABLECREATE TABLE creates a new table and defines its columns, types, and constraints. PostgreS...
CREATE INDEXCREATE INDEX builds an index on a table or materialized view so queries avoid full scans. ...
CREATE VIEWCREATE VIEW saves a query as a reusable virtual table. A view stores no data of its own: e...
CREATE MATERIALIZED VIEWCREATE MATERIALIZED VIEW materializes the result of a query into a real table on disk, tra...
CREATE SEQUENCECREATE SEQUENCE creates a standalone generator of integers, read with nextval(). A sequenc...
CHECKA CHECK constraint requires the values in a column or group of columns to satisfy a given ...
Constraint indexPrimary keys, unique constraints and foreign keys are all implemented with indexes underne...
CREATE INDEX CONCURRENTLYA plain CREATE INDEX holds a SHARE lock on the table, blocking INSERT / UPDATE / DELETE — ...
D
DOUBLE PRECISIONDOUBLE PRECISION matches C's double: 8 bytes with 53 mantissa bits, about 15 to 16 decimal...
DATEDATE represents a calendar date with no time and no time zone, ranging from 4713 BC to 587...
date_trunc(text, timestamp)date_trunc() cuts a timestamp down to a chosen unit — day, hour, month — and returns the s...
DELETEDELETE removes rows from a table matching a WHERE condition. It proceeds row by row, fires...
DROP TABLEDROP TABLE removes a table along with its indexes, constraints, triggers, and all of its d...
DROP INDEXDROP INDEX removes an index that is no longer needed, reclaiming space and speeding up wri...
DEFAULTDEFAULT supplies a fallback value for a column, applied automatically whenever an INSERT o...
DEFERRABLEPostgreSQL can postpone checking foreign keys, unique and exclusion constraints until comm...
DOMAINA domain is a reusable custom type that bundles a value range, a default and NOT NULL into...
E
extract(field from timestamp)extract() pulls an individual part out of a date or timestamp — year, month, day, hour, an...
EXPLAINEXPLAIN shows the plan the planner picked for a statement: sequential scan or index scan, ...
EXCLUDEEXCLUDE is a PostgreSQL-only constraint kind that defines conflicts with a comparison oper...
F
FOREIGN KEYA foreign key enforces referential integrity: every child row must point at a row that rea...
file_fdwfile_fdw is also a foreign data wrapper, but what it reads is not another database — it re...
G
greatest(anycompatible, ...)greatest() returns the largest of its arguments and least() the smallest. All arguments mu...
GRANTGRANT gives privileges on an object to a role. PostgreSQL's permission model is role-centr...
GENERATED columnA generated column hands the computation to the database: the value follows from an expres...
GINGIN (Generalized Inverted Index) splits each element of a composite value into its own pos...
GiSTGiST (Generalized Search Tree) is an extensible index framework: instead of requiring sort...
H
HASHA HASH index hashes keys into fixed-length buckets. It supports equality lookups (=, IN) o...
I
INTEGERINTEGER (also spelled INT4) is the workhorse integer type in PostgreSQL: 4 bytes, ranging ...
IDENTITYIDENTITY is the SQL-standard mechanism for auto-increment columns, supported by PostgreSQL...
INTERVALINTERVAL represents a span of time, stored internally as separate month, day and time comp...
INSERTINSERT adds new rows to a table. It accepts multiple rows in a single statement — a multi-...
INSERT ... ON CONFLICTINSERT ... ON CONFLICT reroutes an insert that would violate a unique key: DO NOTHING skip...
IDENTITYIDENTITY is the SQL-standard way to declare an auto-incrementing column. Unlike SERIAL, wh...
J
JSONBJSONB is PostgreSQL's binary JSON type. It parses the document, stores it reordered by key...
jsonb_build_object(...)jsonb_build_object() constructs a JSONB object from alternating key and value arguments, w...
L
length(text)length() returns the number of characters in a string, and is the workhorse for input vali...
lower(text)lower() returns the string with all letters converted to lower case. It is the standard wa...
lpad(text, integer, text)lpad() pads a string on the left with a fill character (a space by default) until it reach...
LIKELIKE matches text against an SQL pattern. % matches any sequence of characters including n...
M
MONEYMONEY is PostgreSQL's historical currency type. Internally it keeps the amount in a 64-bit...
md5(text)md5() returns the MD5 digest of the input as a fixed 32-character hexadecimal string. It i...
mod(numeric, numeric)mod(y, x) returns the remainder of dividing y by x, with the dividend first and the diviso...
N
NUMERICNUMERIC is PostgreSQL's exact decimal type, and DECIMAL is a fully equivalent spelling. It...
nullif(anycompatible, anycompatible)nullif(a, b) returns NULL when a and b are equal, and otherwise returns a unchanged. Its c...
now()now() returns the start time of the current transaction as a timestamp with time zone. It ...
nextval(regclass)nextval() advances a sequence by one and returns the new value — the mechanism behind auto...
NOTNOT is a unary logical operator that flips a boolean: true becomes false, false becomes tr...
NOT NULLNOT NULL declares that a column always holds a value. It is more precise than CHECK and le...
O
OROR joins two boolean conditions and yields true when either side is true. It also follows ...
P
position(text in text)position() returns the 1-based index of the first occurrence of a substring, and is a comm...
power(numeric, numeric)power(a, b) returns a raised to the b-th power, which comes up for exponential growth, com...
PRIMARY KEYA primary key identifies each row uniquely. It carries both UNIQUE and NOT NULL semantics,...
pgcryptopgcrypto ships digest(), hmac() and gen_random_bytes() as cryptographic primitives, plus t...
pg_trgmpg_trgm splits text into three-character trigrams and indexes them, which enables similari...
postgres_fdwpostgres_fdw is a foreign data wrapper that exposes tables from another PostgreSQL instanc...
pgvectorpgvector adds a vector type and a family of distance operators to PostgreSQL, letting you ...
pg_stat_statementspg_stat_statements accumulates, per normalized statement, the number of calls, total and m...
R
REALREAL is PostgreSQL's single-precision floating-point type, the counterpart of C's float, o...
replace(text, text, text)replace() swaps every occurrence of the from substring for the to substring and returns th...
round(numeric, integer)round() rounds a value to the given number of decimal places, or to a whole number when th...
REFRESH MATERIALIZED VIEWREFRESH MATERIALIZED VIEW recomputes the defining query and replaces the stored result. A ...
REVOKEREVOKE takes back privileges that were granted earlier, mirroring GRANT. It can withdraw a...
S
SMALLINTSMALLINT is PostgreSQL's smallest integer type, occupying 2 bytes with a range of -32768 t...
SERIALSERIAL is not a real storage type but a PostgreSQL pseudo-type: writing SERIAL is shorthan...
substring(text from text)substring(string from pattern) extracts a piece of a string using PostgreSQL's POSIX regul...
split_part(text, text, integer)split_part() cuts a string on a delimiter and returns the nth field. It is the most direct...
string_agg(anyelement, text)string_agg() is an aggregate that joins the values of a group into a single string using a...
SELECTSELECT is the core command for reading data in PostgreSQL, retrieving rows from one or mor...
SP-GiSTSP-GiST (Space-partitioned GiST) is GiST's close relative: it partitions data into disjoin...
T
TEXTTEXT is the string type without a length ceiling and the preferred choice for string handl...
TIMETIME expresses a moment within a day, with neither date nor time zone, ranging from 00:00:...
TIMESTAMPTIMESTAMP (without time zone) combines a date and a time of day, ranging from 4713 BC to 2...
TIMESTAMPTZTIMESTAMPTZ denotes an absolute instant: it is stored internally as UTC and converted to l...
trim(text)trim() strips unwanted characters from both ends of a string — the first step when cleanin...
to_jsonb(anyelement)to_jsonb() converts any SQL value into JSONB, and a whole row can be converted directly to...
TRUNCATETRUNCATE empties a table in one shot, much faster than row-by-row DELETE. It rewrites the ...
Table constraint vs column constraintPostgreSQL constraints can be written after a column definition (column level) or after th...
U
UUIDUUID is a 128-bit universally unique identifier. PostgreSQL stores it as 16 bytes and comp...
upper(text)upper() returns the string with all letters converted to upper case, which is handy for no...
UPDATEUPDATE modifies rows that already exist. It picks target rows with WHERE and assigns new v...
UNIQUEA unique constraint requires the values in a column (or column combination) to be distinct...
uuid-osspuuid-ossp provides UUID generators such as uuid_generate_v4() and uuid_generate_v1(), plus...
V
VARCHARVARCHAR(n) is the variable-length string type, where n caps the maximum number of characte...
VACUUMVACUUM reclaims the space held by dead tuples left behind by UPDATE and DELETE, and refres...
W
WITHWITH lets you define named intermediate result sets (CTEs) ahead of a statement, which the...
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏