User-defined types: Group multiple fields into a single type. Example:
CREATE TYPE address AS (
street TEXT,
city TEXT,
zip VARCHAR(10)
);
9. Other Notable Types
money: Currency value (locale-specific formatting). Example: '$1,000.00'
bytea: Raw binary data ("BLOB" equivalent). Example: '\xDEADBEEF'
hstore: Key-value store (extension required). Example: '"color"=>"red", "size"=>"large"'
ltree: Hierarchical tree structures (extension). Example: 'Top.Science.Astronomy'
Key Features of PostgreSQL Types:
Extensibility: Create custom types (e.g., CREATE TYPE ...).
Rich Operators: E.g., check if a point is inside a circle (circle @> point).
Indexing Support: GIN/GiST indexes for jsonb, geometric types, and full-text search.
Functions: Built-in functions for types (e.g., jsonb_path_query(), point_distance()).
For example, querying a jsonb field:
SELECT profile->>'name' FROM users WHERE profile @> '{"age": 30}';
These types enable PostgreSQL to handle specialized use cases like geospatial data, network management, JSON APIs, and scientific applications more efficiently than standard SQL.