1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
CREATE TABLE demo_common(
int_ int primary key,
/*有长度限制,最多n个字符,text 变长无长度限制*/
varchar_ varchar(40),
text_ text,
/*60.8888,高精度计算(eg:货币金额),速度币decimal慢,精度允许的最大值为1000*/
numeric_ numeric(6,4),
decimal_ decimal,
/*
自增整数 smallserial,serial和bigserial不是真正的类型,仅标识作用,相当于AUTO_INCREMENT 属性
*/
serial_ serial,
/*
money值可以被转换为numeric而不丢失精度。 转换为其他类型可能丢失精度
*/
money_ money,
/*存储二进制串*/
bytea_ bytea,
boolean_ boolean, /*真:true yes on 1 / 假:false no off 0*/
bit_ bit(8),/*位串 一个位串值对于每8位的组需要一个字节 */
uuid_ uuid, /*uuid a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11 (核心数据库不包含任何用于产生UUID的函数)*/
json_ json,
jsonb_ jsonb,/*jsonb json 输入格式一直,区别jsonb输入会慢一点,处理速度比json快,不需要解析(输入的时候提前做好),jsonb列直接支持索引(json只能通过建函数索引),在jsonb上面建gin索引比btree好*/
array_ int2[] /*text[] text[][]*/
);
drop table demo_common
select * from demo_common
/*money*/
SELECT '12.34'::float8::numeric::money;
SELECT '52093.89'::money::numeric::float8;
SELECT NULL::boolean
SELECT E'\\xDEADBEEF';
INSERT INTO demo_common
(int_, varchar_ ,text_ , numeric_, decimal_, money_, bytea_ ,boolean_ ,bit_ ,uuid_,
json_,
jsonb_,
array_
)
VALUES
(2000,'varchar' ,'text','60.8888','88.6666','¥12.34','\\x10',true ,B'01000000','a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',
'{"bar": "baz", "balance": 7.77, "active":false}',
'{"bar": "baz", "balance": 7.77, "active":false}',
'{1,2,3,4}' /*ARRAY[1, 2, 3, 4]*/
)
|