man postgres/tables-and-types
lesson 2 of 34 · Querying
Tables and the types worth knowing
What does this return?
SELECT 7 / 2 AS a, 7 / 2.0 AS b, 0.1::float8 + 0.2::float8 AS c, 0.1 + 0.2 AS d;a | b | c | d ---+--------------------+---------------------+----- 3 | 3.5000000000000000 | 0.30000000000000004 | 0.3 (1 row)
Four small sums, three kinds of answer. 7 / 2 is 3, because both
operands are integers and integer division drops the fraction. 7 / 2.0
is a decimal with sixteen digits after the point. And the two versions of
0.1 + 0.2 disagree, because the first adds binary floating-point numbers
and the second adds decimals.
In PostgreSQL every value has a type, every column has a declared type, and
the type of every expression is settled when the query is parsed, before a
single row is read. The type decides which operator runs (integer division
and numeric division are different functions that share the name /),
which values a column accepts, and how values compare, sort and print. This
lesson goes through the types most tables are built from, and the mistake
each one invites.
The data
The customers and orders from the first lesson are here unchanged, plus a product list that uses most of the types in this lesson:
CREATE TABLE products (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
public_id uuid NOT NULL DEFAULT uuidv7() UNIQUE,
name text NOT NULL,
origin varchar(20) NOT NULL,
price numeric(6,2) NOT NULL,
weight_g integer NOT NULL,
organic boolean NOT NULL DEFAULT false
);
The setup script inserts four products and gives neither an
id nor a public_id: the table generates both. The public_id values
are different on every run, so the examples never print them.
SELECT id, name, origin, price, weight_g, organic
FROM products
ORDER BY id;id | name | origin | price | weight_g | organic ----+-------------+----------+-------+----------+--------- 1 | Yirgacheffe | Ethiopia | 14.50 | 250 | t 2 | Huila | Colombia | 12.00 | 250 | f 3 | Santos | Brazil | 9.75 | 500 | f 4 | Kiambu | Kenya | 16.25 | 250 | t (4 rows)
A query can also describe the table. psql’s \d products prints much the
same, but meta-commands like \d belong to psql and don’t run in the boxes
on this page:
SELECT column_name, data_type, is_nullable, column_default, is_identity
FROM information_schema.columns
WHERE table_name = 'products'
ORDER BY ordinal_position;column_name | data_type | is_nullable | column_default | is_identity -------------+-------------------+-------------+----------------+------------- id | bigint | NO | | YES public_id | uuid | NO | uuidv7() | NO name | text | NO | | NO origin | character varying | NO | | NO price | numeric | NO | | NO weight_g | integer | NO | | NO organic | boolean | NO | false | NO (7 rows)
As in the first lesson, each box shows the output recorded with psql against PostgreSQL 19.0, and “run” executes it in this page in PGlite. One difference shows up in this lesson: each recording starts from a fresh copy of the data, but the page keeps one database for all its boxes, so a box that inserts a row leaves it there for the boxes after it. Otherwise every box gives the same output live as recorded.
Every literal has a type
pg_typeof names the type of any expression. Applied to bare constants:
SELECT pg_typeof(1), pg_typeof(3000000000), pg_typeof(1.5), pg_typeof(1e3), pg_typeof('1');pg_typeof | pg_typeof | pg_typeof | pg_typeof | pg_typeof -----------+-----------+-----------+-----------+----------- integer | bigint | numeric | numeric | unknown (1 row)
A whole number is an integer if it fits in one, otherwise a bigint
(and a numeric beyond that). A number with a decimal point or an exponent
is a numeric, not a floating-point value: that is why 0.1 + 0.2 above
came out exact. A quoted literal is unknown: it has no type until the
context gives it one. In WHERE ordered_on = '2026-03-02' the other side
of = is a date, so the string is read as a date. The section on casts
comes back to this.
Integers
There are three integer types: smallint (2 bytes, up to 32,767),
integer (4 bytes, up to 2,147,483,647) and bigint (8 bytes, up to
9,223,372,036,854,775,807). Going past the end is an error, never a silent
wrap-around:
SELECT 2147483647 + 1;ERROR: integer out of range
The result of integer + integer is an integer. Make one side a
bigint and the addition is done in bigint:
SELECT 2147483647::bigint + 1;?column? ------------ 2147483648 (1 row)
Division of two integers truncates toward zero, and % gives the
remainder. If either side is a numeric, so is the result:
SELECT 7 / 2 AS q, -7 / 2 AS neg, 7 % 2 AS r, 7 / 2::numeric AS exact;q | neg | r | exact ---+-----+---+-------------------- 3 | -3 | 1 | 3.5000000000000000 (1 row)
Aggregates widen their result so that they don’t fall into the same traps.
sum of an integer column is a bigint, so it does not overflow at two
billion; avg of one is a numeric, so it keeps the fraction; count is
always a bigint:
SELECT pg_typeof(sum(weight_g)) AS sum,
pg_typeof(avg(weight_g)) AS avg,
pg_typeof(count(*)) AS count
FROM products;sum | avg | count --------+---------+-------- bigint | numeric | bigint (1 row)
integer is the usual choice for quantities and counts. For a key that a
sequence hands out, bigint costs four more bytes per row and removes a
limit that a busy table can reach in its lifetime. Changing an integer
key to bigint later rewrites the table, and the columns that reference
it need the same change before they can hold the new values.
numeric against double precision
numeric stores decimal digits, as many as you need. Addition,
subtraction and multiplication are exact. double precision (also spelled
float8) is the IEEE 754 binary floating-point number that most
programming languages call a double: 8 bytes, at least 15 significant
decimal digits, fast arithmetic done by the hardware. But it stores binary
fractions, and most decimal fractions, 0.1 among them, have no exact binary
form. Every value is rounded to the nearest double, and so is the result of
every operation.
Step through ten additions of 0.1 in both types:
Ten running sums of 0.1, as double precision and as numeric. The numeric sum reads 0.1, 0.2 and so on up to exactly 1.0. The double precision sum reads 0.30000000000000004 at row 3, 0.7999999999999999 at row 8 and 0.9999999999999999 at row 10, and is not equal to 1 at the end. (This figure steps through a recorded run; it needs JavaScript.)
Each row is a running sum computed by PostgreSQL 19.0 with a window
function (a later lesson), recorded by the lesson’s trace.py. The shaded row is
the one just added; outlined rows are those where the double precision sum
is not the double nearest to the decimal value beside it.
The double precision sum is never far off, and it is not always visibly
off: at rows 4 to 7 the rounding happens to land on the right value again.
But it ends at 0.9999999999999999, and = 1 is false. Comparing doubles
with = is a bug waiting for the right data.
numeric(p, s)
A column can limit a numeric: numeric(6,2) holds up to six digits, two
of them after the point. A value with more decimals is rounded to two, and
ties round away from zero:
SELECT 13.455::numeric(6,2) AS "13.455", (-13.455)::numeric(6,2) AS "-13.455",
13.454::numeric(6,2) AS "13.454";13.455 | -13.455 | 13.454 --------+---------+-------- 13.46 | -13.46 | 13.45 (1 row)
A value with too many digits before the point is an error, and the DETAIL line says what fits:
SELECT 12345.678::numeric(6,2);ERROR: numeric field overflow DETAIL: A field with precision 6, scale 2 must round to an absolute value less than 10^4.
The two types round differently. numeric rounds ties away from zero,
while double precision rounds ties to the even neighbour, as IEEE 754
does (on most machines: the documentation leaves it to the platform). The same applies when a value is cast to an integer:
SELECT 2.5::integer AS from_numeric,
2.5::float8::integer AS from_float8,
round(2.5) AS round_numeric,
round(2.5::float8) AS round_float8; from_numeric | from_float8 | round_numeric | round_float8
--------------+-------------+---------------+--------------
3 | 2 | 3 | 2
(1 row)Both types also accept 'Infinity', '-Infinity' and 'NaN' (quoted,
since to the parser they are strings). IEEE 754 says NaN equals nothing,
not even itself; PostgreSQL makes NaN equal to NaN and larger than every
other value, so that columns holding it can be sorted and indexed:
SELECT 'NaN'::float8 = 'NaN'::float8 AS nan_equals_nan,
'NaN'::float8 > 'Infinity'::float8 AS nan_above_infinity;nan_equals_nan | nan_above_infinity ----------------+-------------------- t | t (1 row)
Which to use: numeric for money and for anything that must add up to the
cent, as orders.total and products.price do. Its arithmetic is done in
software and is much slower than the other numeric types, which matters
only when a query does a lot of it. double precision for measured
quantities (temperatures, distances, scores), where 15 digits is more than
the measurement has, and for heavy arithmetic. There is also a money
type, whose number of decimals and output format follow the lc_monetary
setting; numeric avoids that dependency. real (float4) keeps only
about 6 significant digits, which is rarely enough.
text, varchar(n) and char(n)
text holds a string of any length, and it is what most string functions
take and return. varchar(n) (character varying(n)) is the same with a
limit of n characters. Storing a longer value is an error (unless the
extra characters are all spaces, which are cut off):
INSERT INTO products (name, origin, price, weight_g)
VALUES ('House blend', 'Ethiopia, Colombia and Brazil', 11.00, 1000);ERROR: value too long for type character varying(20)
An explicit cast to the same type, though, cuts the value to fit without a word. The SQL standard requires both behaviours:
SELECT 'Ethiopia, Colombia and Brazil'::varchar(20) AS origin;origin ---------------------- Ethiopia, Colombia a (1 row)
char(n) (character(n)) pads values with spaces to exactly n characters,
and then treats trailing spaces as if they were not there. It compares
equal to a value with different trailing spaces, reports the length
without them, and drops them when converted to text, as || does. But
the padding is stored:
SELECT 'ab'::char(5) = 'ab'::char(2) AS equal,
length('ab'::char(5)) AS length,
octet_length('ab'::char(5)) AS bytes,
'ab'::char(5) || '|' AS concatenated;equal | length | bytes | concatenated -------+--------+-------+-------------- t | 2 | 5 | ab| (1 row)
In PostgreSQL the three types perform the same, apart from the work of
checking a limit and the storage of char(n)’s padding, which usually
makes it the slowest. Use text. When a length limit is a real rule of the
data rather than a guess, varchar(n) states it, and so does a
CHECK (char_length(origin) <= 20) constraint, which can also express
rules a length cannot.
boolean
A boolean is true or false (or NULL, which is the next lesson). Input
accepts several spellings: true/false, yes/no, on/off, 1/0,
and unambiguous prefixes of these such as t and f. psql prints t and
f:
SELECT 'yes'::boolean, 'off'::boolean, '1'::boolean, 't'::boolean;bool | bool | bool | bool ------+------+------+------ t | f | t | t (1 row)
A boolean column is already a condition. WHERE organic is the whole test;
= true adds nothing:
SELECT name, price
FROM products
WHERE organic
ORDER BY name;name | price -------------+------- Kiambu | 16.25 Yirgacheffe | 14.50 (2 rows)
uuid, and uuidv7
A uuid is a 128-bit value, written as 32 hex digits in five groups and
stored in 16 bytes, less than half of what the same value takes as text.
PostgreSQL generates two versions. gen_random_uuid() (also called
uuidv4()) is random apart from the bits that mark its version.
uuidv7(), new in PostgreSQL 18, begins with the current Unix time in
milliseconds, followed by a finer fraction of the millisecond, and fills
the rest with random bits. uuid_extract_version reads the version back:
SELECT uuid_extract_version(gen_random_uuid()) AS random,
uuid_extract_version(uuidv7()) AS time_ordered; random | time_ordered
--------+--------------
4 | 7
(1 row)Because the time comes first, version 7 values sort in the order they were made: exactly so within one session, and as closely as the clocks agree across sessions. Here are a thousand of each, generated in one query and checked for whether sorting by the UUID gives back the order of generation:
WITH ids AS (
SELECT n, uuidv7() AS v7, gen_random_uuid() AS v4
FROM generate_series(1, 1000) AS n
)
SELECT array_agg(n ORDER BY v7) = array_agg(n ORDER BY n) AS v7_in_order,
array_agg(n ORDER BY v4) = array_agg(n ORDER BY n) AS v4_in_order
FROM ids;v7_in_order | v4_in_order -------------+------------- t | f (1 row)
That order is what makes version 7 a good primary key: new keys land at the end of the index, as a sequence’s do, instead of at random places all over it (the lesson on indexes shows why that matters). The price is that the creation time can be read by anyone who has the id. This one, written out by hand for the example, carries 2 March 2026, 09:14:07.250 UTC:
SELECT uuid_extract_timestamp('019cadd3-8812-7a41-9c3e-5b2f0d6e8a17') AT TIME ZONE 'UTC'
AS created;created ------------------------ 2026-03-02 09:14:07.25 (1 row)
(AT TIME ZONE 'UTC' keeps the output from depending on the session’s time
zone; the lesson on dates and times explains it.)
When to use a uuid at all: when ids are made outside the database (by
clients, or by several databases), or are shown to people and should not
be guessable or countable. Use gen_random_uuid() when the creation time
must not leak, uuidv7() otherwise. A bigint is half the size and easier
to read in a log. The products table uses both: id for joins inside the
database, public_id for anything outside it.
Identity columns
GENERATED ALWAYS AS IDENTITY attaches a sequence to the column, and every
insert that does not name the column takes the next value from it:
INSERT INTO products (name, origin, price, weight_g)
VALUES ('Antigua', 'Guatemala', 13.40, 250)
RETURNING id, name, organic;id | name | organic ----+---------+--------- 5 | Antigua | f (1 row)
RETURNING sends back the inserted row, including what the defaults
filled in: the new id, and organic from its DEFAULT false. This is
the box that changes the page’s database: run it twice and the second run
adds a second Antigua, with id 6.
ALWAYS means an insert cannot supply its own value, unless it says
OVERRIDING SYSTEM VALUE, which is meant for loading data that already has
ids:
INSERT INTO products (id, name, origin, price, weight_g)
VALUES (10, 'Antigua', 'Guatemala', 13.40, 250);ERROR: cannot insert a non-DEFAULT value into column "id" DETAIL: Column "id" is an identity column defined as GENERATED ALWAYS. HINT: Use OVERRIDING SYSTEM VALUE to override.
The other form, GENERATED BY DEFAULT AS IDENTITY, accepts a supplied
value without complaint, and the sequence does not notice. Insert id 5 by
hand while the sequence has handed out 1 to 4, and the next ordinary insert
gets 5 from the sequence and fails on the primary key. ALWAYS prevents
that mistake.
Two more facts about sequences. They are not part of transactions: a value,
once handed out, is not taken back, even when the insert that took it
fails or is rolled back. So identity values are unique but have gaps,
and max(id) is not a row count. And the older serial type (bigserial
for bigint) does much the same job with a sequence and a column default.
It is PostgreSQL’s own shorthand; identity columns are the SQL standard
form, and the better choice for new tables.
Casts
There are three ways to write a conversion. CAST(x AS type) is the SQL
standard; x::type is PostgreSQL’s shorter form; and type 'literal'
works for constants only:
SELECT CAST('42' AS integer) + 1 AS a, '42'::integer + 1 AS b, date '2026-03-02' + 1 AS c;a | b | c ----+----+------------ 43 | 43 | 2026-03-03 (1 row)
A string that does not parse as the target type is an error, and psql points at it:
SELECT '4 2'::integer;ERROR: invalid input syntax for type integer: "4 2"
LINE 1: SELECT '4 2'::integer;
^In an expression, PostgreSQL converts on its own only within a family of
types: an integer to a larger integer, to numeric or to a floating-point
type, and a numeric to a floating-point type. Between families, such
as text and numbers, it does not. The exception is a quoted literal: it is
unknown, and takes whatever type the context needs. So a quoted number
compared with an integer column works:
SELECT id, total
FROM orders
WHERE customer_id = '1'
ORDER BY id;id | total -----+------- 101 | 42.00 103 | 60.00 107 | 27.50 (3 rows)
A value that already is text is another matter. There is no = between
integer and text, and PostgreSQL will not guess which side to convert.
This is the error an application gets when it sends a parameter typed as
text for an integer column:
SELECT id, total
FROM orders
WHERE customer_id = '1'::text
ORDER BY id;ERROR: operator does not exist: integer = text
LINE 3: WHERE customer_id = '1'::text
^
DETAIL: No operator of that name accepts the given argument types.
HINT: You might need to add explicit type casts.Fix it on the parameter’s side (= $1::integer, or by declaring the
parameter’s type in the driver), not by casting the column.
customer_id::text = '1' returns the right rows too, but it converts every
row’s value to compare it, and an index on customer_id cannot help with
an expression on it.
In short
- Keys:
bigint GENERATED ALWAYS AS IDENTITY; auuid(version 7 unless the time must stay private) when ids are made or shown outside the database. - Money and exact decimals:
numeric, with(p, s)when the scale is part of the meaning. - Measurements:
double precision, never compared with=. - Counts and quantities:
integer; watch integer division. - Strings:
text, with a CHECK when a limit is a rule. - Flags:
boolean, tested asWHERE flag. - Timestamps:
timestamptz, the subject of a later lesson.
Try it yourself
Use any box above: press “edit”, replace the query, press “run”. The queries in the answers can be pasted the same way.
- Predict the value and type of each column, then run it:
SELECT 1 / 3 * 3 AS a, 1 / 3.0 * 3 AS b, 1::float8 / 3 * 3 AS c;
Answer
a is 0: 1 / 3 is integer division, which gives 0. b is
0.99999999999999999999, a numeric: 1 / 3.0 is computed to 20 decimal
places and multiplying by 3 is exact, so the missing part shows. c is 1:
the double nearest to a third, times 3, rounds to exactly 1.
SELECT 1 / 3 * 3 AS a, 1 / 3.0 * 3 AS b, 1::float8 / 3 * 3 AS c;
pg_typeof shows the three types (integer, numeric, double precision):
SELECT pg_typeof(1 / 3 * 3) AS a, pg_typeof(1 / 3.0 * 3) AS b, pg_typeof(1::float8 / 3 * 3) AS c;
- Compute the average product weight as
sum(weight_g) / count(*). Why does it differ fromavg(weight_g), and how do you fix it withoutavg?
Answer
sum returns a bigint and so does count, so the division is integer
division: 1250 / 4 gives 312 instead of 312.5. Make either side a
numeric:
SELECT sum(weight_g) / count(*) AS truncated,
sum(weight_g)::numeric / count(*) AS exact,
avg(weight_g) AS avg
FROM products;
exact and avg both give 312.5000000000000000. (With the Antigua row
from the insert box above, all three give 300.)
- The origin of a new product is
'Papua New Guinea Highlands'. What doesSELECT 'Papua New Guinea Highlands'::varchar(20)return, and what would an INSERT intoproductsdo with the same value?
Answer
The cast cuts the string to its first 20 characters, Papua New Guinea Hig,
without an error. The INSERT fails with value too long for type character varying(20), as the House blend example did.
SELECT 'Papua New Guinea Highlands'::varchar(20) AS origin;
uuidv7takes an optionalintervalthat shifts the time it embeds. Make a UUID dated one day in the past and check its timestamp withuuid_extract_timestamp.
Answer
The extracted timestamp is a day before the current time. Comparing it
with now() gives a result that does not depend on when you run it, t:
SELECT uuid_extract_timestamp(uuidv7(interval '-1 day')) < now() - interval '23 hours'
AS a_day_old;
- Find the products whose price per kilogram is over 40.00, showing that price rounded to cents.
Answer
price is numeric and weight_g an integer, so price / weight_g is
a numeric division and keeps the fraction. Multiply by 1000 for
kilograms and round to two places:
SELECT name, round(price / weight_g * 1000, 2) AS per_kg
FROM products
WHERE price / weight_g * 1000 > 40
ORDER BY per_kg DESC;
Kiambu (65.00), Yirgacheffe (58.00) and Huila (48.00) qualify; Santos, at 19.50, does not. If you ran the Antigua insert in this page, Antigua (53.60) is in the list too.
Sources
The PostgreSQL 19 documentation:
- Numeric types:
integer ranges,
numericprecision and scale and its rounding, floating point and its special values, and the serial types. - Character types:
text,varchar(n)andchar(n), the error against the explicit cast, and the note that they perform alike. - Boolean type and UUID type.
- UUID functions:
gen_random_uuid,uuidv4,uuidv7and the extraction functions. - Identity columns: ALWAYS against BY DEFAULT.
- Sequence manipulation functions: why sequences leave gaps.
- Type casts, and Operators in the chapter on type conversion: how an operator is chosen for the types of its operands.
- System information functions:
pg_typeof. - Monetary types.
ls postgres/
Querying
- 01 How a SELECT runs, clause by clause draftThe logical order of FROM, WHERE, GROUP BY, HAVING, SELECT, DISTINCT, ORDER BY and LIMIT, and the everyday errors it explains.
- 02 Tables and the types worth knowing draftinteger and bigint, numeric against double precision, text, boolean, uuid (including uuidv7), identity columns, and casts.
- 03 NULL and three-valued logic draftWhy x = NULL is never true, IS DISTINCT FROM, coalesce, NOT IN with a NULL in the list, and how aggregates skip NULLs.
- 04 Joins draftInner, left, right, full and cross joins; ON against USING; semi- and anti-joins with EXISTS; the rows an outer join adds.
- 05 Aggregates and GROUP BY plannedcount(*) against count(x), FILTER, ordered string_agg and array_agg, any_value, and grouping by a primary key.
- 06 Subqueries and set operations plannedScalar, IN, EXISTS, ANY and ALL subqueries, correlated subqueries, and UNION, INTERSECT and EXCEPT with and without ALL.
- 07 Sorting and paging plannedNULLS FIRST and LAST, collations, ties and FETCH ... WITH TIES, and keyset pagination instead of large OFFSETs.
- 08 Dates, times and time zones plannedtimestamp against timestamptz, the session time zone, intervals, date_trunc, and generate_series for calendars.
- 09 Changing data plannedINSERT, UPDATE and DELETE with RETURNING, including OLD and NEW values in RETURNING, and UPDATE ... FROM.
Analytical queries
- 10 Window functions plannedPARTITION BY, ORDER BY and frames; ranking, running totals and moving averages; lag, lead and first_value with IGNORE NULLS.
- 11 WITH queries plannedCommon table expressions for readability, MATERIALIZED and NOT MATERIALIZED, and data-modifying statements in WITH.
- 12 Recursive queries plannedWITH RECURSIVE over trees and graphs, the SEARCH and CYCLE clauses, and how to stop a recursion that never ends.
- 13 LATERAL plannedSubqueries and functions that see the row beside them: top N per group, and set-returning functions per row.
- 14 GROUPING SETS, ROLLUP and CUBE plannedSeveral groupings in one query, subtotals and grand totals, and telling them apart with GROUPING().
Richer data
- 15 JSONB plannedOperators, containment, jsonpath, updating documents, and the GIN indexes that make the queries fast.
- 16 SQL/JSON and JSON_TABLE plannedThe standard JSON functions: JSON_VALUE, JSON_QUERY, JSON_EXISTS, IS JSON, and JSON_TABLE to turn documents into rows.
- 17 Arrays plannedBuilding and slicing arrays, unnest WITH ORDINALITY, = ANY, array_agg, array_sort, and when a table is better.
- 18 Ranges and temporal keys plannedRange and multirange types, overlap and containment, exclusion constraints, and primary keys WITHOUT OVERLAPS.
- 19 Full-text search plannedtsvector and tsquery, configurations and dictionaries, ranking, highlighting, and indexing a search column.
Keeping data correct
- 20 Constraints plannedCHECK, NOT NULL, UNIQUE with NULLS NOT DISTINCT, foreign keys and their actions, deferrable constraints, NOT VALID.
- 21 Generated columns plannedColumns computed from others, virtual (the default) or stored, and what each costs on reads and writes.
- 22 Transactions and isolation levels plannedWhat READ COMMITTED, REPEATABLE READ and SERIALIZABLE let two sessions see, the anomalies each allows, and retrying serialization failures.
- 23 Row locks and queues plannedSELECT ... FOR UPDATE and its weaker forms, NOWAIT, SKIP LOCKED for job queues, and advisory locks.
- 24 Upsert and MERGE plannedINSERT ... ON CONFLICT DO NOTHING, DO UPDATE and DO SELECT; MERGE with WHEN NOT MATCHED BY SOURCE and RETURNING merge_action().
Performance from the query side
- 25 Indexes plannedWhat a B-tree index can answer: column order in multicolumn indexes, partial, expression and covering (INCLUDE) indexes.
- 26 GIN, GiST, BRIN and hash plannedWhich queries each index type serves, with the operators that use it: containment, overlap, nearest neighbour, ranges of a big table.
- 27 Reading EXPLAIN plannedPlan nodes, estimated against actual rows, buffers, and the questions to ask of a slow plan. How statistics feed the estimates.
- 28 Partitioning plannedRange, list and hash partitions, partition pruning in plans, and attaching and detaching partitions.
Logic and access in the database
- 29 Views and materialized views plannedNaming a query, updatable views, WITH CHECK OPTION, and refreshing a materialized view concurrently.
- 30 SQL and PL/pgSQL functions plannedFunctions and procedures, volatility, set-returning functions, and PL/pgSQL control flow and error handling.
- 31 Triggers plannedRow and statement triggers, BEFORE and AFTER, transition tables, and keeping an audit log.
- 32 LISTEN and NOTIFY plannedMessages between sessions, how they interact with transactions, and a small change feed.
- 33 Row-level security plannedPolicies that filter rows per role, USING against WITH CHECK, and the roles that bypass them.
- 34 Extensions worth knowing plannedpg_trgm, pgcrypto, citext, btree_gist, postgres_fdw and pg_stat_statements: what each adds and when to reach for it.