PostgreSQL – DATA TYPES
PostgreSQL is a popular open-source relational database management system (RDBMS) that supports a wide range of data types to accommodate different kinds of data, from basic integers and text to more complex structures like arrays and JSON documents. Here are some of the common data types provided by PostgreSQL:
- Numeric Types:
integer
(int): A 32-bit signed integer.bigint
: A 64-bit signed integer.numeric
ordecimal
: Arbitrary precision decimal number.
- Character Types:
char(n)
orcharacter(n)
: Fixed-length character string.varchar(n)
orcharacter varying(n)
: Variable-length character string.text
: Variable-length character string with no limit.
- Binary Data Types:
bytea
: Binary data, useful for storing binary files like images or documents.
- Date and Time Types:
date
: Date (year, month, day).time
: Time of day (hour, minute, second).timestamp
: Date and time (including fractions of a second).interval
: Time interval.
- Boolean Type:
boolean
: Represents true or false values.
- Enumerated Types:
enum
: User-defined enumeration type.
- Geometric Types:
point
: Represents a point in a two-dimensional space.line
: Represents an infinite line in a two-dimensional space.lseg
: Represents a line segment in a two-dimensional space.box
: Represents a rectangular box in a two-dimensional space.path
: Represents a path consisting of points connected by straight line segments.polygon
: Represents a closed polygonal path.
- Network Address Types:
inet
: IPv4 or IPv6 network address.cidr
: IPv4 or IPv6 network address with a specified subnet mask.
- Text Search Types:
tsvector
: Text search document.tsquery
: Text search query.
- UUID Type:
uuid
: Universally Unique Identifier.
- JSON Types:
json
: JSON data.jsonb
: Binary representation of JSON data, allowing for efficient querying.
- Array Types:
- Arrays of various data types, such as
integer[]
ortext[]
.
- Arrays of various data types, such as
- Composite Types:
- User-defined composite types.
- Range Types:
int4range
,numrange
,daterange
, etc. Represent ranges of various data types.
- HStore Type:
hstore
: A key-value store within a single PostgreSQL value.
- Domain Types:
- User-defined data types based on other base data types.
These are just some of the data types available in PostgreSQL. Each data type has specific characteristics, storage requirements, and functions associated with it. You can use these data types to model and store your data effectively within PostgreSQL databases.