Niraj Zade | Website is a work in progress.

Postgres - data types

2024 Oct 13  |  4 min read  |  tags: postgres 2 dbms 2


All info has been lifted from postgres documentation, and dumped here for the convenience of me and my colleagues.

https://www.postgresql.org/docs/current/datatype.html

Financial

Name Aliases Description
money currency amount

DO NOT USE THE MONEY DATA TYPE.

More info - pg - don't use money

Note - The currency associated with money type changes with the database's locale, and this can cause discrepancies. For storing financial amounts, it is still recommended to either use integer or use numeric (decimal is just an alias of numeric).

And indicate currency using standard currency codes (ISO 4217)

Geometric

Name Aliases Description
box rectangular box on a plane
circle circle on a plane
line infinite line on a plane
lseg line segment on a plane
path geometric path on a plane
point geometric point on a plane
polygon closed geometric path on a plane

Json, xml

Name Aliases Description
json textual JSON data
jsonb binary JSON data, decomposed
xml XML data

Logical

Name Aliases Description
bit [ (_`n`_) ] fixed-length bit string
bit varying [ (_`n`_) ] varbit [ (_`n`_) ] variable-length bit string
boolean bool logical Boolean (true/false)
bytea binary data (“byte array”)

Numeric

Name Aliases Description
bigint int8 signed eight-byte integer
bigserial serial8 autoincrementing eight-byte integer
double precision float8 double precision floating-point number (8 bytes)
integer int, int4 signed four-byte integer
numeric [ (_`p`_, _`s`_) ] decimal [ (_`p`_, _`s`_) ] exact numeric of selectable precision
real float4 single precision floating-point number (4 bytes)
smallint int2 signed two-byte integer
smallserial serial2 autoincrementing two-byte integer
serial serial4 autoincrementing four-byte integer

Specialized

Name Aliases Description
cidr IPv4 or IPv6 network address
inet IPv4 or IPv6 host address
macaddr MAC (Media Access Control) address
macaddr8 MAC (Media Access Control) address (EUI-64 format)
txid_snapshot user-level transaction ID snapshot (deprecated; see pg_snapshot)
uuid universally unique identifier
Name Aliases Description
pg_lsn PostgreSQL Log Sequence Number
pg_snapshot user-level transaction ID snapshot
tsquery text search query
tsvector text search document
txid_snapshot user-level transaction ID snapshot (deprecated; see pg_snapshot)

String

Name Aliases Description
character [ (_`n`_) ] char [ (_`n`_) ] fixed-length character string
character varying [ (_`n`_) ] varchar [ (_`n`_) ] variable-length character string
text variable-length character string

Time

Name Aliases Description
date calendar date (year, month, day)
interval [ _`fields`_ ] [ (_`p`_) ] time span
time [ (_`p`_) ] [ without time zone ] time of day (no time zone)
time [ (_`p`_) ] with time zone timetz time of day, including time zone
timestamp [ (_`p`_) ] [ without time zone ] date and time (no time zone)
timestamp [ (_`p`_) ] with time zone timestamptz date and time, including time zone

Table Of Contents:

All Articles

Blog

Resources