8. 資料型別
PostgreSQL 內建一套豐富的資料型別供用戶使用。使用者也可以使用 CREATE TYPE 指令讓 PostgreSQL 增加新的資料型別。
Table 8.1 列出所有內建的通用資料型別。大多數列在「Aliases」中的替代名稱是由於在 PostgreSQL 內部使用的歷史因素。此外,還有一些內部使用或不建議使用的資料型別,但這裡並沒有列出。
Table 8.1. Data Types
Name | Aliases | Description |
|
| signed eight-byte integer |
|
| autoincrementing eight-byte integer |
| fixed-length bit string | |
|
| variable-length bit string |
|
| logical Boolean (true/false) |
| rectangular box on a plane | |
| binary data (“byte array”) | |
|
| fixed-length character string |
|
| variable-length character string |
| IPv4 or IPv6 network address | |
| circle on a plane | |
| calendar date (year, month, day) | |
|
| double precision floating-point number (8 bytes) |
| IPv4 or IPv6 host address | |
|
| signed four-byte integer |
| time span | |
| textual JSON data | |
| binary JSON data, decomposed | |
| infinite line on a plane | |
| line segment on a plane | |
| MAC (Media Access Control) address | |
| MAC (Media Access Control) address (EUI-64 format) | |
| currency amount | |
|
| exact numeric of selectable precision |
| geometric path on a plane | |
| PostgreSQLLog Sequence Number | |
| geometric point on a plane | |
| closed geometric path on a plane | |
|
| single precision floating-point number (4 bytes) |
|
| signed two-byte integer |
|
| autoincrementing two-byte integer |
|
| autoincrementing four-byte integer |
| variable-length character string | |
| time of day (no time zone) | |
|
| time of day, including time zone |
| date and time (no time zone) | |
|
| date and time, including time zone |
| text search query | |
| text search document | |
| user-level transaction ID snapshot | |
| universally unique identifier | |
| XML data |
相容性
以下資料型別(或其拼寫方式)是由 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
.
每種資料型別都具有其明確的輸入和輸出功能外部表示法。許多內建的資料型別都有明顯的外部格式。但是,有幾種資料型別是 PostgreSQL 獨有的,比如幾何路徑,或者有幾種可能的格式,像是日期和時間型別。某些輸入和輸出功能是不可逆的,意即,與原始輸入相比,輸出功能的結果可能會失去一些精確度。
Last updated