跳至主要內容

KlustronDB大约 3 分钟

Chapter 8. Data Types

Table of Contents

8.1. Numeric Types : 8.1.1. Integer Types

[8.1.2. Arbitrary Precision Numbers](datatype-numeric.md#DATATYPE-NUMERIC-DECIMAL)

[8.1.3. Floating-Point Types](datatype-numeric.md#DATATYPE-FLOAT)

[8.1.4. Serial Types](datatype-numeric.md#DATATYPE-SERIAL)

8.2. Monetary Types

8.3. Character Types

8.4. Binary Data Types : 8.4.1. bytea Hex Format

[8.4.2. `bytea` Escape Format](datatype-binary.md#id-1.5.7.12.10)

8.5. Date/Time Types : 8.5.1. Date/Time Input

[8.5.2. Date/Time Output](datatype-datetime.md#DATATYPE-DATETIME-OUTPUT)

[8.5.3. Time Zones](datatype-datetime.md#DATATYPE-TIMEZONES)

[8.5.4. Interval Input](datatype-datetime.md#DATATYPE-INTERVAL-INPUT)

[8.5.5. Interval Output](datatype-datetime.md#DATATYPE-INTERVAL-OUTPUT)

8.6. Boolean Type

8.7. Enumerated Types : 8.7.1. Declaration of Enumerated Types

[8.7.2. Ordering](datatype-enum.md#id-1.5.7.15.6)

[8.7.3. Type Safety](datatype-enum.md#id-1.5.7.15.7)

[8.7.4. Implementation Details](datatype-enum.md#id-1.5.7.15.8)

8.8. Geometric Types : 8.8.1. Points

[8.8.2. Lines](datatype-geometric.md#DATATYPE-LINE)

[8.8.3. Line Segments](datatype-geometric.md#DATATYPE-LSEG)

[8.8.4. Boxes](datatype-geometric.md#id-1.5.7.16.8)

[8.8.5. Paths](datatype-geometric.md#id-1.5.7.16.9)

[8.8.6. Polygons](datatype-geometric.md#DATATYPE-POLYGON)

[8.8.7. Circles](datatype-geometric.md#DATATYPE-CIRCLE)

8.9. Network Address Types : 8.9.1. inet

[8.9.2. `cidr`](datatype-net-types.md#DATATYPE-CIDR)

[8.9.3. `inet` vs. `cidr`](datatype-net-types.md#DATATYPE-INET-VS-CIDR)

[8.9.4. `macaddr`](datatype-net-types.md#DATATYPE-MACADDR)

[8.9.5. `macaddr8`](datatype-net-types.md#DATATYPE-MACADDR8)

8.10. Bit String Types

8.11. Text Search Types : 8.11.1. tsvector

[8.11.2. `tsquery`](datatype-textsearch.md#DATATYPE-TSQUERY)

8.12. UUID Type

8.13. XML Type : 8.13.1. Creating XML Values

[8.13.2. Encoding Handling](datatype-xml.md#id-1.5.7.21.6)

[8.13.3. Accessing XML Values](datatype-xml.md#id-1.5.7.21.7)

8.14. JSON Types : 8.14.1. JSON Input and Output Syntax

[8.14.2. Designing JSON documents effectively](datatype-json.md#JSON-DOC-DESIGN)

[8.14.3. `jsonb` Containment and Existence](datatype-json.md#JSON-CONTAINMENT)

[8.14.4. `jsonb` Indexing](datatype-json.md#JSON-INDEXING)

[8.14.5. Transforms](datatype-json.md#id-1.5.7.22.18)

8.15. Arrays : 8.15.1. Declaration of Array Types

[8.15.2. Array Value Input](arrays.md#ARRAYS-INPUT)

[8.15.3. Accessing Arrays](arrays.md#ARRAYS-ACCESSING)

[8.15.4. Modifying Arrays](arrays.md#ARRAYS-MODIFYING)

[8.15.5. Searching in Arrays](arrays.md#ARRAYS-SEARCHING)

[8.15.6. Array Input and Output Syntax](arrays.md#ARRAYS-IO)

8.16. Composite Types : 8.16.1. Declaration of Composite Types

[8.16.2. Constructing Composite Values](rowtypes.md#id-1.5.7.24.6)

[8.16.3. Accessing Composite Types](rowtypes.md#ROWTYPES-ACCESSING)

[8.16.4. Modifying Composite Types](rowtypes.md#id-1.5.7.24.8)

[8.16.5. Using Composite Types in Queries](rowtypes.md#ROWTYPES-USAGE)

[8.16.6. Composite Type Input and Output Syntax](rowtypes.md#ROWTYPES-IO-SYNTAX)

8.17. Range Types : 8.17.1. Built-in Range Types

[8.17.2. Examples](rangetypes.md#RANGETYPES-EXAMPLES)

[8.17.3. Inclusive and Exclusive Bounds](rangetypes.md#RANGETYPES-INCLUSIVITY)

[8.17.4. Infinite (Unbounded) Ranges](rangetypes.md#RANGETYPES-INFINITE)

[8.17.5. Range Input/Output](rangetypes.md#RANGETYPES-IO)

[8.17.6. Constructing Ranges](rangetypes.md#RANGETYPES-CONSTRUCT)

[8.17.7. Discrete Range Types](rangetypes.md#RANGETYPES-DISCRETE)

[8.17.8. Defining New Range Types](rangetypes.md#RANGETYPES-DEFINING)

[8.17.9. Indexing](rangetypes.md#RANGETYPES-INDEXING)

[8.17.10. Constraints on Ranges](rangetypes.md#RANGETYPES-CONSTRAINT)

8.18. Domain Types

8.19. Object Identifier Types

8.20. pg_lsn Type

8.21. Pseudo-Types

PostgreSQL has a rich set of native data types available to users. Users can add new types to PostgreSQL using the CREATE TYPE command.

Table 8.1 shows all the built-in general-purpose data types. Most of the alternative names listed in the “Aliases” column are the names used internally by PostgreSQL for historical reasons. In addition, some internally used or deprecated types are available, but are not listed here.

Table 8.1. Data Types

NameAliasesDescription
bigintint8signed eight-byte integer
bigserialserial8autoincrementing eight-byte integer
bit [ (n) ]fixed-length bit string
bit varying [ (n) ]varbit [ (n) ]variable-length bit string
booleanboollogical Boolean (true/false)
boxrectangular box on a plane
byteabinary data (“byte array”)
character [ (n) ]char [ (n) ]fixed-length character string
character varying [ (n) ]varchar [ (n) ]variable-length character string
cidrIPv4 or IPv6 network address
circlecircle on a plane
datecalendar date (year, month, day)
double precisionfloat8double precision floating-point number (8 bytes)
inetIPv4 or IPv6 host address
integerint, int4signed four-byte integer
interval [ fields ] [ (p) ]time span
jsontextual JSON data
jsonbbinary JSON data, decomposed
lineinfinite line on a plane
lsegline segment on a plane
macaddrMAC (Media Access Control) address
macaddr8MAC (Media Access Control) address (EUI-64 format)
moneycurrency amount
numeric [ (p, s) ]decimal [ (p, s) ]exact numeric of selectable precision
pathgeometric path on a plane
pg_lsnPostgreSQL Log Sequence Number
pointgeometric point on a plane
polygonclosed geometric path on a plane
realfloat4single precision floating-point number (4 bytes)
smallintint2signed two-byte integer
smallserialserial2autoincrementing two-byte integer
serialserial4autoincrementing four-byte integer
textvariable-length character string
time [ (p) ] [ without time zone ]time of day (no time zone)
time [ (p) ] with time zonetimetztime of day, including time zone
timestamp [ (p) ] [ without time zone ]date and time (no time zone)
timestamp [ (p) ] with time zonetimestamptzdate and time, including time zone
tsquerytext search query
tsvectortext search document
txid_snapshotuser-level transaction ID snapshot
uuiduniversally unique identifier
xmlXML data

Compatibility

The following types (or spellings thereof) are specified by SQL: bigint, bit, bit varying, boolean, char, character varying, character, varchar, date, double precision, integer, interval, numeric, decimal, real, smallint, time (with or without time zone), timestamp (with or without time zone), xml.

Each data type has an external representation determined by its input and output functions. Many of the built-in types have obvious external formats. However, several types are either unique to PostgreSQL, such as geometric paths, or have several possible formats, such as the date and time types. Some of the input and output functions are not invertible, i.e., the result of an output function might lose accuracy when compared to the original input.