Types & casting
◈ 2 cardsThe core types, and converting between them.
Pick the right type
Postgres is strongly typed. The everyday types:
int/bigint— whole numbers;numeric(p,s)— exact decimals (money!);real/double precision— floatstext/varchar(n)— stringsboolean— true/falsedate,timestamp,timestamptz,interval— timeuuid,json/jsonb, arrays — covered next
Convert with ::type (or CAST(x AS type)):
SELECT '42'::int, 3.7::int, 'true'::boolean, now()::date;