PostgreSQL 数据类型一览
下表显示了所有内置的通用数据类型。
“别名”列中列出的大多数备选名称都是PostgreSQL内部出于历史原因使用的名称。
此外,一些内部使用或不推荐使用的类型也可用,但此处未列出。
根据我的使用频率进行分类。
常用
| 类型 | 别名 | 描述 | 
|---|---|---|
| bigint | int8 | 8个字节的整型 | 
| bigserial | serial8 | 8个字节的自增整型 | 
| boolean | bool | 布尔类型 | 
| character [ (n) ] | char [ (n) ] | 定长字符串 | 
| character varying [ (n) ] | varchar [ (n) ] | 变长字符串 | 
| date | 日期(年,月,日) | |
| double precision | float8 | 双精度浮点数 (8个字节) | 
| integer | int,int4 | 四个字节的整型 | 
| numeric [ (p, s) ] | decimal [ (p, s) ] | 可选精度的精确数值 | 
| smallint | int2 | 两个字节的整型 | 
| smallserial | serial2 | 两个字节的自增整型 | 
| serial | serial4 | 四个字节的自增整型 | 
| text | 可变长度字符串(不限制字符长度) | |
| time [ (p) ] [ without time zone ] | 一天当中的时间(不带时区) | |
| time [ (p) ] with time zone | timetz | 一天当中的时间(带时区) | 
| timestamp [ (p) ] [ without time zone ] | 日期和时间(不带时区) | |
| timestamp [ (p) ] with time zone | timestamptz | 日期和时间(带时区) | 
其他
| 类型 | 别名 | 描述 | 
|---|---|---|
| bit [ (n) ] | fixed-length bit string | |
| bit varying [ (n) ] | varbit [ (n) ] | |
| box | rectangular box on a plane | |
| bytea | binary data (“byte array”) | |
| cidr | IPv4 or IPv6 network address | |
| circle | circle on a plane | |
| inet | IPv4 or IPv6 host address | |
| interval [ fields ] [ (p) ] | time span | |
| json | textual JSON data | |
| jsonb | binary JSON data, decomposed | |
| line | infinite line on a plane | |
| lseg | line segment on a plane | |
| macaddr | MAC (Media Access Control) address | |
| macaddr8 | MAC (Media Access Control) address (EUI-64 format) | |
| money | currency amount | |
| path | geometric path on a plane | |
| pg_lsn | PostgreSQL Log Sequence Number | |
| pg_snapshot | user-level transaction ID snapshot | |
| point | geometric point on a plane | |
| polygon | closed geometric path on a plane | |
| real | float4 | single precision floating-point number (4 bytes) | 
| tsquery | text search query | |
| tsvector | text search document | |
| txid_snapshot | user-level transaction ID snapshot (deprecated; see pg_snapshot) | |
| uuid | universally unique identifier | |
| xml | 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.
相关链接
OB links
OB tags
#PostgreSQL
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 z2huo!
 评论