TcaplusDB Client - select命令(查询主键索引)
TcaplusDB Client的使用方法参见文档。
1. 功能说明
根据用户指定的数据所有主键字段的值,查询整条数据的所有字段值或部分字段的值,如果没有匹配的记录,将会返回错误。
如果需要对查询到文件中的记录进行修改,再更新到服务端,请使用load命令。
请注意,对于List表,load命令会直接插入一条新记录,如果需要更新服务端的原有记录,请使用update命令并指定index。
请注意,保存查询结果的文件名不能以数字开头。
2. 启始版本
3.40.0
3. 命令语法
select key1, key2, key3, value1, value2 [into result.csv] from table [where key1 = 1 and key2 = "abc" and key3=1] [and -index = 1] [\P] [\G] [\S] [\N] [\A] [using tdr] [encode]
select * [into result.xml] from table [where key1 = 1 and key2 = "abc" and key3=1] [and -index = 1] using tdr [\P];
参数说明:
参数 | PB表 | TDR表 | 必填项 |
---|---|---|---|
table | 表格的名字 | 表格的名字 | 是 |
key | 主键字段名,必须指定所有主键字段的值 | 主键字段名,必须指定所有主键字段的值 | 是 |
value | 非主键字段名 | 非主键字段名 | 至少一个或 * |
-index | Generic表:不支持 List表:如果指定“-index”会返回相同Key下的第index条记录,如果不指定 "-index", 则返回相同Key下的所有记录 |
Generic表:不支持 List表:如果指定“-index”会返回相同Key下的第index条记录,如果不指定 "-index", 则返回相同Key下的所有记录 |
否 |
\P | 打印时延数据 | 打印时延数据 | 否 |
\G | 竖排打印 | 竖排打印 | 否 |
\S | 从从副本读取数据 | 从从副本读取数据 | 否,不填默认从主副本读取数据 |
\N | 不打印字段名 | 不打印字段名 | 否,不填默认打印字段名 |
\A | 将查询结果追加写到结果文件 | 将查询结果追加写到结果文件 | 否,不填默认将查询结果覆盖写到结果文件 |
into | 输出数据到文件 | 输出数据到文件 | 否 |
using tdr | 不支持 | 如果需要使用该参数,则在启动TcaplusDB Client时,就要通过启动参数指定与目标表对应的TDR文件 | 否 |
encode | 不支持(回车字符或不可见字符已预处理) | 指定该参数后,导出命令会将含有回车字符或不可见字符的string类型字段值进行BASE64编码后,再输出 注意:只指定了 using tdr 参数时,该参数才生效 |
否 |
where语句中除了指定主键,在3.55.0之后版本,还支持使用
AND
结合更灵活的过滤条件,见详细语法。
4. 命令示例
表定义详见示例表定义。
tcaplus> select * from test_table where gameid=1234 and itemid=12323 and name=testname;
+------+------+----------+------+----+-----+
|gameid|itemid|name |typeid|Data|uname|
+------+------+----------+------+----+-----+
|1234 |12323 |"testname"|0 |9 |"ab" |
+------+------+----------+------+----+-----+
1 records selectd, select time: 9802 us
tcaplus> select uname from test_table where gameid=1234 and itemid=12323 and name=testname;
+------+------+----------+-----+
|gameid|itemid|name |uname|
+------+------+----------+-----+
|1234 |12323 |"testname"|"ab" |
+------+------+----------+-----+
1 records selectd, select time: 9457 us
tcaplus> select * into test.csv from test_table where gameid=1234 and itemid=12323 and name=testname;
1 records are stored to test.csv, select time: 10198 us
tcaplus> select * from test_table where gameid=1234 and itemid=12323 and name=testname \P \G;
gameid: 1234
itemid: 12323
name: "testname"
typeid: 0
Data: 9
uname: "ab"
API ---- -1us --->ProxyFront---- 10us --->ProxyEnd--- 364us --->SvrMainStart
| | | |381us
|11380us |4138us |4104us SvrWorkerStart
| | | |61us
API <--- 34197us ----ProxyFront<--- 24us ----ProxyEnd<-- 3298us ----SvrWorkerEnd
1 records selectd, select time: 11380 us
tcaplus> select * into table_list.xml from table_list where uin=99 and name = "99" and key1=99 using tdr;
11 records are stored to table_list.xml, select time: 135299 us
tcaplus> select c_string from table_list where uin=99 and name = "99" and key1=99;
+---+----+----+--------+
|uin|name|key1|c_string|
+---+----+----+--------+
|99 |"99"|99 |" " |
+---+----+----+--------+
|99 |"99"|99 |"" |
+---+----+----+--------+
|99 |"99"|99 |"" |
+---+----+----+--------+
|99 |"99"|99 |"" |
+---+----+----+--------+
|99 |"99"|99 |"" |
+---+----+----+--------+
|99 |"99"|99 |" " |
+---+----+----+--------+
|99 |"99"|99 |" " |
+---+----+----+--------+
|99 |"99"|99 |" " |
+---+----+----+--------+
|99 |"99"|99 |" " |
+---+----+----+--------+
|99 |"99"|99 |" " |
+---+----+----+--------+
|99 |"99"|99 |" " |
+---+----+----+--------+
11 records selectd, select time: 102572 us
tcaplus> select c_string from table_list where uin=99 and name = "99" and key1=99 and -index=9;
+---+----+----+--------+
|uin|name|key1|c_string|
+---+----+----+--------+
|99 |"99"|99 |" " |
+---+----+----+--------+
1 records selectd, select time: 9886 us
tcaplus> select * from table_list_bin where uin=1 and name="3" encode;
+------+---+------+-----+-----+-----+------+------+------------+------------+-------------+
|-index|uin|name |level|count|items|name_1|name_2|binary_count|binary |single_struct|
+------+---+------+-----+-----+-----+------+------+------------+------------+-------------+
|0 |1 |"Mw=="|1 |0 |0x |"" |"" |5 |0x1232123443|0x |
+------+---+------+-----+-----+-----+------+------+------------+------------+-------------+
|1 |1 |"Mw=="|1 |0 |0x |"" |"" |5 |0x1232123443|0x |
+------+---+------+-----+-----+-----+------+------+------------+------------+-------------+
2 records selected, select time: 4333 us
tcaplus> select * from table_list_bin where uin=1 and name="3";
+------+---+----+-----+-----+-----+------+------+------------+------------+-------------+
|-index|uin|name|level|count|items|name_1|name_2|binary_count|binary |single_struct|
+------+---+----+-----+-----+-----+------+------+------------+------------+-------------+
|0 |1 |"3" |1 |0 |0x |"" |"" |5 |0x1232123443|0x |
+------+---+----+-----+-----+-----+------+------+------------+------------+-------------+
|1 |1 |"3" |1 |0 |0x |"" |"" |5 |0x1232123443|0x |
+------+---+----+-----+-----+-----+------+------+------------+------------+-------------+
2 records selected, select time: 4335 us
5. 常见错误
参考常见错误文档。
6. 相关文档
[TDR Generic表][C++ SDK]查询单条数据接口说明。
[TDR Generic表][Java SDK]查询单条数据接口说明。
[TDR Generic表][Go SDK]查询单条数据接口说明。
[TDR List表][C++ SDK]查询单条数据接口说明。
[TDR List表][Java SDK]查询单条数据接口说明。
[TDR List表][Go SDK]查询单条数据接口说明。
[PB Generic表][C++ SDK]查询单条数据接口说明。
[PB Generic表][Go SDK]查询单条数据接口说明。
[PB Generic表][RESTFul API]查询单条数据接口说明。