插入数据
xstore表插入数据和行存表语法一致,使用insert into 语句对表插入数据,插入子查询的结果示例如下:
teledb=# create table xt (a int ,b int ,c text) using xstore;
CREATE TABLE
teledb=# insert into xt select 1,i,'c_'||i from generate_series(1,20) i;
INSERT 0 20
teledb=# select * from xt;
a | b | c
---+----+------
1 | 1 | c_1
1 | 2 | c_2
1 | 3 | c_3
1 | 4 | c_4
1 | 5 | c_5
1 | 6 | c_6
1 | 7 | c_7
1 | 8 | c_8
1 | 9 | c_9
1 | 10 | c_10
1 | 11 | c_11
1 | 12 | c_12
1 | 13 | c_13
1 | 14 | c_14
1 | 15 | c_15
1 | 16 | c_16
1 | 17 | c_17
1 | 18 | c_18
1 | 19 | c_19
1 | 20 | c_20
(20 rows)
更新数据
xstore表更新数据和行存表语法一致,使用update 命令对指定列或多列数据进行更新,操作如下:
teledb=# update xt set b=b+a;
UPDATE 20
teledb=# select * from xt;
a | b | c
---+----+------
1 | 2 | c_1
1 | 3 | c_2
1 | 4 | c_3
1 | 5 | c_4
1 | 6 | c_5
1 | 7 | c_6
1 | 8 | c_7
1 | 9 | c_8
1 | 10 | c_9
1 | 11 | c_10
1 | 12 | c_11
1 | 13 | c_12
1 | 14 | c_13
1 | 15 | c_14
1 | 16 | c_15
1 | 17 | c_16
1 | 18 | c_17
1 | 19 | c_18
1 | 20 | c_19
1 | 21 | c_20
(20 rows)
删除数据
xstore表更新数据和行存表语法一致,使用delete 命令删除指定条件的行记录数据,操作如下:
teledb=# delete from xt where b<3;
DELETE 1
teledb=# select * from xt;
a | b | c
---+----+------
1 | 3 | c_2
1 | 4 | c_3
1 | 5 | c_4
1 | 6 | c_5
1 | 7 | c_6
1 | 8 | c_7
1 | 9 | c_8
1 | 10 | c_9
1 | 11 | c_10
1 | 12 | c_11
1 | 13 | c_12
1 | 14 | c_13
1 | 15 | c_14
1 | 16 | c_15
1 | 17 | c_16
1 | 18 | c_17
1 | 19 | c_18
1 | 20 | c_19
1 | 21 | c_20
(19 rows)
单表查询
xstore查询数据和行存表语法一致,使用select 命令查询指定条件的行记录数据,查询 xt表中b 字段值大于 5 的操作如下:
teledb=# select * from xt where b>5 order by b desc limit 2;
a | b | c
---+----+------
1 | 21 | c_20
1 | 20 | c_19
(2 rows)
多表查询
xstore表多表查询和行存表语法一致,使用select 和 join 命令查询指定条件的行记录数据,查询 xt表和xt1表中b字段值一样的查询如下:
teledb=# select xt.c,xt1.c from xt join xt1 on xt.b=xt1.b limit 10;
c | c
------+------
c_4 | c_5
c_5 | c_6
c_7 | c_8
c_8 | c_9
c_11 | c_12
c_12 | c_13
c_14 | c_15
c_16 | c_17
c_18 | c_19
c_2 | c_3
(10 rows)