添加链接
注册
登录
link管理
链接快照平台
输入网页链接,自动生成快照
标签化管理网页链接
相关文章推荐
笑点低的人字拖
·
济南大学2024年硕士研究生复试名单_教育屋
·
1 月前
·
风流倜傥的木瓜
·
2024年西安新房房价走势图,2024西安楼 ...
·
2 月前
·
年轻有为的香烟
·
刑事检察工作白皮书(2023)_中华人民共和 ...
·
2 月前
·
强悍的台灯
·
中共八大以来的历届中央政治局常委_改革大数据 ...
·
3 月前
·
强悍的太阳
·
June 2021 - US ...
·
5 月前
·
link管理
›
查询数据 | TDengine 文档 | 涛思数据
https://docs.taosdata.com/develop/query-data/
文雅的炒粉
6 月前
Skip to main content
</a><a href="https://www.taosdata.com/events/tdcon2024?utm_source=tdcn&utm_medium=doc&utm_campaign=menu" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">用户大会</a><a href="https://www.taosdata.com/blog" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">博客</a><a href="https://www.taosdata.com/contactUs" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">联系我们</a><a href="https://cloud.taosdata.com/" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">Cloud</a><div class="navbarSearchContainer_Bca1"/></div></div><div role="presentation" class="navbar-sidebar__backdrop"/></nav><div id="__docusaurus_skipToContent_fallback" class="main-wrapper mainWrapper_z2l0"><div class="docsWrapper_hBAB"><button aria-label="Scroll back to top" class="clean-btn theme-back-to-top-button backToTopButton_sjWU" type="button"/><div class="docRoot_UBD9"><aside class="theme-doc-sidebar-container docSidebarContainer_YfHR"><div class="sidebarViewport_aRkj"><div class="sidebar_gi4H sidebarWithHideableNavbar_vOD8"><a href="https://www.taosdata.com" target="_blank" rel="noopener noreferrer" tabindex="-1" class="sidebarLogo_YnPk"><img src="/img/site-logo.png" alt="" class="themedComponent_mlkZ themedComponent--light_NVdE"/><img src="/img/site-logo.png" alt="" class="themedComponent_mlkZ themedComponent--dark_xIcU"/><b/></a><div class="sidebarTop_Qw2W"><div class="versionDropdownWrapper_Qxj6"><select name="version" class="versionSelect_lz6N"><option value="3.0" selected="">v3.0</option><option value="2.6">v2.6</option><option value="2.4">v2.4</option><option value="cloud">Cloud</option><option value="2.0">v2.0</option><option value="1.6">v1.6</option></select></div><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><svg width="20" height="20" class="DocSearch-Search-Icon" viewbox="0 0 20 20"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"/></svg><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"/></button></div><nav aria-label="Docs sidebar" class="menu thin-scrollbar menu_Y1UP"><ul class="theme-doc-sidebar-menu menu__list"><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="/">文档首页</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="/intro/">产品简介</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="/concept/">基本概念</a></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" href="/get-started/">立即开始</a><button aria-label="Expand sidebar category '立即开始'" type="button" class="clean-btn menu__caret"/></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--active" aria-expanded="true" href="/develop/">开发指南</a><button aria-label="Collapse sidebar category '开发指南'" type="button" class="clean-btn menu__caret"/></div><ul style="display:block;overflow:visible;height:auto" class="menu__list"><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/develop/connect/">建立连接</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/develop/model/">数据建模</a></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" tabindex="0" href="/develop/insert-data/">写入数据</a><button aria-label="Expand sidebar category '写入数据'" type="button" class="clean-btn menu__caret"/></div></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link menu__link--active" aria-current="page" tabindex="0" href="/develop/query-data/">查询数据</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/develop/stream/">流式计算</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/develop/tmq/">数据订阅</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/develop/cache/">缓存</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/develop/udf/">用户定义函数</a></li></ul></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" href="/connector/">连接器</a><button aria-label="Expand sidebar category '连接器'" type="button" class="clean-btn menu__caret"/></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" href="/deployment/">部署集群</a><button aria-label="Expand sidebar category '部署集群'" type="button" class="clean-btn menu__caret"/></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" href="/taos-sql/">SQL 手册</a><button aria-label="Expand sidebar category 'SQL 手册'" type="button" class="clean-btn menu__caret"/></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" href="/reference/">参考手册</a><button aria-label="Expand sidebar category '参考手册'" type="button" class="clean-btn menu__caret"/></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" href="/operation/">运维指南</a><button aria-label="Expand sidebar category '运维指南'" type="button" class="clean-btn menu__caret"/></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" href="/third-party/">第三方工具</a><button aria-label="Expand sidebar category '第三方工具'" type="button" class="clean-btn menu__caret"/></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" href="/tdinternal/">技术内幕</a><button aria-label="Expand sidebar category '技术内幕'" type="button" class="clean-btn menu__caret"/></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" href="/application/">应用实践</a><button aria-label="Expand sidebar category '应用实践'" type="button" class="clean-btn menu__caret"/></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" href="/train-faq/">FAQ 及其他</a><button aria-label="Expand sidebar category 'FAQ 及其他'" type="button" class="clean-btn menu__caret"/></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="/releases/tdengine/">发布历史</a></div></li></ul></nav></div></div></aside><main class="docMainContainer_TBSr"><div class="container padding-top--md padding-bottom--lg"><div class="row"><div class="col docItemCol_VOVn"><div class="docItemContainer_Djhp"><article><div class="tocCollapsible_ETCw theme-doc-toc-mobile tocMobile_ITEo"><button type="button" class="clean-btn tocCollapsibleButton_TO0P">On this page</button></div><div class="theme-doc-markdown markdown"><header><h1>查询数据</h1></header><h2 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="主要查询功能">主要查询功能<a href="#主要查询功能" class="hash-link" aria-label="Direct link to 主要查询功能" title="Direct link to 主要查询功能"></a></h2> <p>TDengine 采用 SQL 作为查询语言。应用程序可以通过 REST API 或连接器发送 SQL 语句,用户还可以通过 TDengine 命令行工具 taos 手动执行 SQL 即席查询(Ad-Hoc Query)。TDengine 支持如下查询功能:</p> <li>单列、多列数据查询</li> <li>标签和数值的多种过滤条件:>, <, =, <>, like 等</li> <li>聚合结果的分组(Group by)、排序(Order by)、约束输出(Limit/Offset)</li> <li>时间窗口(Interval)、会话窗口(Session)和状态窗口(State_window)等窗口切分聚合查询</li> <li>数值列及聚合结果的四则运算</li> <li>时间戳对齐的连接查询(Join Query: 隐式连 接)操作</li> <li>多种聚合/计算函数: count, max, min, avg, sum, twa, stddev, leastsquares, top, bottom, first, last, percentile, apercentile, last_row, spread, diff 等</li> <p>例如:在命令行工具 taos 中,从表 d1001 中查询出 voltage > 215 的记录,按时间降序排列,仅仅输出 2 条。</p> <div class="language-sql codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-sql codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">taos</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">select</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">from</span><span class="token plain"> d1001 </span><span class="token keyword" style="color:#00009f">where</span><span class="token plain"> voltage </span><span class="token operator" style="color:#393A34">></span><span class="token plain"> </span><span class="token number" style="color:#36acaa">215</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">order</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">by</span><span class="token plain"> ts </span><span class="token keyword" style="color:#00009f">desc</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">limit</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">2</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> ts </span><span class="token operator" style="color:#393A34">|</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">current</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">|</span><span class="token plain"> voltage </span><span class="token operator" style="color:#393A34">|</span><span class="token plain"> phase </span><span class="token operator" style="color:#393A34">|</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token operator" style="color:#393A34">=</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token number" style="color:#36acaa">2018</span><span class="token operator" style="color:#393A34">-</span><span class="token number" style="color:#36acaa">10</span><span class="token operator" style="color:#393A34">-</span><span class="token number" style="color:#36acaa">03</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">14</span><span class="token plain">:</span><span class="token number" style="color:#36acaa">38</span><span class="token plain">:</span><span class="token number" style="color:#36acaa">16.800</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">|</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">12.30000</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">|</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">221</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">|</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">0.31000</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">|</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token number" style="color:#36acaa">2018</span><span class="token operator" style="color:#393A34">-</span><span class="token number" style="color:#36acaa">10</span><span class="token operator" style="color:#393A34">-</span><span class="token number" style="color:#36acaa">03</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">14</span><span class="token plain">:</span><span class="token number" style="color:#36acaa">38</span><span class="token plain">:</span><span class="token number" style="color:#36acaa">15.000</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">|</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">12.60000</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">|</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">218</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">|</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">0.33000</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">|</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain">Query OK</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">2</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">row</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">s</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">in</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">set</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token number" style="color:#36acaa">0.001100</span><span class="token plain">s</span><span class="token punctuation" style="color:#393A34">)</span><br/></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewbox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewbox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/></svg></span></button></div></div></div> <p>为满足物联网场景的需求,TDengine 支持几个特殊的函数,比如 twa(时间加权平均),spread (最大值与最小值的差),last_row(最后一条记录)等,更多与物联网场景相关的函数将添加进来。</p> <p>具体的查询语法请看 <a href="/taos-sql/select/">TDengine SQL 的数据查询</a> 章节。</p> <h2 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="多表聚合查询">多表聚合查询<a href="#多表聚合查询" class="hash-link" aria-label="Direct link to 多表聚合查询" title="Direct link to 多表聚合查询"></a></h2> <p>物联网场景中,往往同一个类型的数据采集点有多个。TDengine 采用超级表(STable)的概念来描述某一个类型的数据采集点,一张普通的表来描述一个具体的数据采集点。同时 TDengine 使用标签来描述数据采集点的静态属性,一个具体的数据采集点有具体的标签值。通过指定标签的过滤条件,TDengine 提供了一高效的方法将超级表(某一类型的数据采集点)所属的子表进行聚合查询。对普通表的聚合函数以及绝大部分操作都适用于超级表,语法完全一样。</p> <h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="示例一">示例一<a href="#示例一" class="hash-link" aria-label="Direct link to 示例一" title="Direct link to 示例一"></a></h3> <p>在 TDengine CLI,查找加利福尼亚州所有智能电表采集的电压平均值,并按照 location 分组。</p> <div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">taos> SELECT AVG(voltage), location FROM meters GROUP BY location;</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> avg(voltage) | location |</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain">===============================================================================================</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> 219.200000000 | California.SanFrancisco |</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> 221.666666667 | California.LosAngeles |</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain">Query OK, 2 rows in database (0.005995s)</span><br/></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewbox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewbox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/></svg></span></button></div></div></div> <h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="示例二">示例二<a href="#示例二" class="hash-link" aria-label="Direct link to 示例二" title="Direct link to 示例二"></a></h3> <p>在 TDengine CLI, 查找 groupId 为 2 的所有智能电表的记录条数,电流的最大值。</p> <div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">taos> SELECT count(*), max(current) FROM meters where groupId = 2;</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> cunt(*) | max(current) |</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain">==================================</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> 5 | 13.4 |</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain">Query OK, 1 row(s) in set (0.002136s)</span><br/></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewbox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewbox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/></svg></span></button></div></div></div> <p>在 <a href="/taos-sql/select/">TDengine SQL 的数据查询</a> 一章,查询类操作都会注明是否支持超级表。</p> <h2 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="降采样查询插值">降采样查询、插值<a href="#降采样查询插值" class="hash-link" aria-label="Direct link to 降采样查询、插值" title="Direct link to 降采样查询、插值"></a></h2> <p>物联网场景里,经常需要通过降采样(down sampling)将采集的数据按时间段进行聚合。TDengine 提供了一个简便的关键词 interval 让按照时间窗口的查询操作变得极为简单。比如,将智能电表 d1001 采集的电流值每 10 秒钟求和</p> <div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">taos> SELECT _wstart, sum(current) FROM d1001 INTERVAL(10s);</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> _wstart | sum(current) |</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain">======================================================</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> 2018-10-03 14:38:00.000 | 10.300000191 |</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> 2018-10-03 14:38:10.000 | 24.900000572 |</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain">Query OK, 2 rows in database (0.003139s)</span><br/></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewbox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewbox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/></svg></span></button></div></div></div> <p>降采样操作也适用于超级表,比如:将加利福尼亚州所有智能电表采集的电流值每秒钟求和</p> <div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">taos> SELECT _wstart, SUM(current) FROM meters where location like "California%" INTERVAL(1s);</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> _wstart | sum(current) |</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain">======================================================</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> 2018-10-03 14:38:04.000 | 10.199999809 |</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> 2018-10-03 14:38:05.000 | 23.699999809 |</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> 2018-10-03 14:38:06.000 | 11.500000000 |</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> 2018-10-03 14:38:15.000 | 12.600000381 |</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> 2018-10-03 14:38:16.000 | 34.400000572 |</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain">Query OK, 5 rows in database (0.007413s)</span><br/></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewbox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewbox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/></svg></span></button></div></div></div> <p>降采样操作也支持时间偏移,比如:将所有智能电表采集的电流值每秒钟求和,但要求每个时间窗口从 500 毫秒开始</p> <div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">taos> SELECT _wstart, SUM(current) FROM meters INTERVAL(1s, 500a);</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> _wstart | sum(current) |</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain">======================================================</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> 2018-10-03 14:38:03.500 | 10.199999809 |</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> 2018-10-03 14:38:04.500 | 10.300000191 |</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> 2018-10-03 14:38:05.500 | 13.399999619 |</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> 2018-10-03 14:38:06.500 | 11.500000000 |</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> 2018-10-03 14:38:14.500 | 12.600000381 |</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> 2018-10-03 14:38:16.500 | 34.400000572 |</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain">Query OK, 6 rows in database (0.005515s)</span><br/></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewbox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewbox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/></svg></span></button></div></div></div> <p>物联网场景里,每个数据采集点采集数据的时间是难同步的,但很多分析算法(比如 FFT)需要把采集的数据严格按照时间等间隔的对齐,在很多系统里,需要应用自己写程序来处理,但使用 TDengine 的降采样操作就轻松解决。</p> <p>如果一个时间间隔里,没有采集的数据,TDengine 还提供插值计算的功能。</p> <p>语法规则细节请见 <a href="/taos-sql/distinguished/">TDengine SQL 的按时间窗口切分聚合</a> 章节。</p> <h2 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="示例代码">示例代码<a href="#示例代码" class="hash-link" aria-label="Direct link to 示例代码" title="Direct link to 示例代码"></a></h2> <h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="查询数据">查询数据<a href="#查询数据" class="hash-link" aria-label="Direct link to 查询数据" title="Direct link to 查询数据"></a></h3> <p>在 <a href="/develop/insert-data/sql-writing/">SQL 写入</a> 一章,我们创建了 power 数据库,并向 meters 表写入了一些数据,以下示例代码展示如何查询这个表的数据。</p> <div class="tabs-container tabList__CuJ"><ul role="tablist" aria-orientation="horizontal" class="tabs"><li role="tab" tabindex="0" aria-selected="true" class="tabs__item tabItem_LNqP tabs__item--active">Java</li><li role="tab" tabindex="-1" aria-selected="false" class="tabs__item tabItem_LNqP">Python</li><li role="tab" tabindex="-1" aria-selected="false" class="tabs__item tabItem_LNqP">Go</li><li role="tab" tabindex="-1" aria-selected="false" class="tabs__item tabItem_LNqP">Rust</li><li role="tab" tabindex="-1" aria-selected="false" class="tabs__item tabItem_LNqP">Node.js</li><li role="tab" tabindex="-1" aria-selected="false" class="tabs__item tabItem_LNqP">C#</li><li role="tab" tabindex="-1" aria-selected="false" class="tabs__item tabItem_LNqP">C</li><li role="tab" tabindex="-1" aria-selected="false" class="tabs__item tabItem_LNqP">PHP</li></ul><div class="margin-top--md"><div role="tabpanel" class="tabItem_Ymn6"><div class="language-java codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-java codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token keyword" style="color:#00009f">package</span><span class="token plain"> </span><span class="token namespace" style="opacity:0.7">com</span><span class="token namespace punctuation" style="opacity:0.7;color:#393A34">.</span><span class="token namespace" style="opacity:0.7">taos</span><span class="token namespace punctuation" style="opacity:0.7;color:#393A34">.</span><span class="token namespace" style="opacity:0.7">example</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token keyword" style="color:#00009f">import</span><span class="token plain"> </span><span class="token import namespace" style="opacity:0.7">java</span><span class="token import namespace punctuation" style="opacity:0.7;color:#393A34">.</span><span class="token import namespace" style="opacity:0.7">sql</span><span class="token import namespace punctuation" style="opacity:0.7;color:#393A34">.</span><span class="token import operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token keyword" style="color:#00009f">public</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">class</span><span class="token plain"> </span><span class="token class-name">RestQueryExample</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">private</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">static</span><span class="token plain"> </span><span class="token class-name">Connection</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">getConnection</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">throws</span><span class="token plain"> </span><span class="token class-name">SQLException</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token class-name">String</span><span class="token plain"> jdbcUrl </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"jdbc:TAOS-RS://localhost:6041/power?user=root&password=taosdata"</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">return</span><span class="token plain"> </span><span class="token class-name">DriverManager</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">getConnection</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">jdbcUrl</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">private</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">static</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">void</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">printRow</span><span class="token punctuation" style="color:#393A34">(</span><span class="token class-name">ResultSet</span><span class="token plain"> rs</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">throws</span><span class="token plain"> </span><span class="token class-name">SQLException</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token class-name">ResultSetMetaData</span><span class="token plain"> meta </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> rs</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">getMetaData</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">for</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token keyword" style="color:#00009f">int</span><span class="token plain"> i </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"> i </span><span class="token operator" style="color:#393A34"><=</span><span class="token plain"> meta</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">getColumnCount</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"> i</span><span class="token operator" style="color:#393A34">++</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token class-name">String</span><span class="token plain"> value </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> rs</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">getString</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">i</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token class-name">System</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">out</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">print</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">value</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token class-name">System</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">out</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">print</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"\t"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token class-name">System</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">out</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">println</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">private</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">static</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">void</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">printColName</span><span class="token punctuation" style="color:#393A34">(</span><span class="token class-name">ResultSet</span><span class="token plain"> rs</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">throws</span><span class="token plain"> </span><span class="token class-name">SQLException</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token class-name">ResultSetMetaData</span><span class="token plain"> meta </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> rs</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">getMetaData</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">for</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token keyword" style="color:#00009f">int</span><span class="token plain"> i </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"> i </span><span class="token operator" style="color:#393A34"><=</span><span class="token plain"> meta</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">getColumnCount</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"> i</span><span class="token operator" style="color:#393A34">++</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token class-name">String</span><span class="token plain"> colLabel </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> meta</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">getColumnLabel</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">i</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token class-name">System</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">out</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">print</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">colLabel</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token class-name">System</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">out</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">print</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"\t"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token class-name">System</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">out</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">println</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">private</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">static</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">void</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">processResult</span><span class="token punctuation" style="color:#393A34">(</span><span class="token class-name">ResultSet</span><span class="token plain"> rs</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">throws</span><span class="token plain"> </span><span class="token class-name">SQLException</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">printColName</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">rs</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">while</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">rs</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">next</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">printRow</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">rs</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">private</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">static</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">void</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">queryData</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">throws</span><span class="token plain"> </span><span class="token class-name">SQLException</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">try</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token class-name">Connection</span><span class="token plain"> conn </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">getConnection</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">try</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token class-name">Statement</span><span class="token plain"> stmt </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> conn</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">createStatement</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token class-name">ResultSet</span><span class="token plain"> rs </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> stmt</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">executeQuery</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"SELECT AVG(voltage) FROM meters GROUP BY location"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">processResult</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">rs</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">public</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">static</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">void</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">main</span><span class="token punctuation" style="color:#393A34">(</span><span class="token class-name">String</span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> args</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">throws</span><span class="token plain"> </span><span class="token class-name">SQLException</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">queryData</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic">// possible output:</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic">// avg(voltage) location</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic">// 222.0 California.LosAngeles</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic">// 219.0 California.SanFrancisco</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewbox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewbox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/></svg></span></button></div></div></div> <p><a href="https://github.com/taosdata/TDengine/blob/main/docs/examples/java/src/main/java/com/taos/example/RestQueryExample.java" target="_blank" rel="noopener noreferrer">查看源码</a></p></div><div role="tabpanel" class="tabItem_Ymn6" hidden=""><p>通过迭代逐行获取查询结果。</p> <div class="language-py codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-py codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token keyword" style="color:#00009f">def</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">query_api_demo</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">conn</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"> taos</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">TaosConnection</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> result</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"> taos</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">TaosResult </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> conn</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">query</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"SELECT tbname, * FROM meters LIMIT 2"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">print</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"field count:"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> result</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">field_count</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">print</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"meta of fields[1]:"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> result</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">fields</span><span class="token punctuation" style="color:#393A34">[</span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">print</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"======================Iterate on result========================="</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">for</span><span class="token plain"> row </span><span class="token keyword" style="color:#00009f">in</span><span class="token plain"> result</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">print</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">row</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic"># field count: 7</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic"># meta of fields[1]: {name: ts, type: 9, bytes: 8}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic"># ======================Iterate on result=========================</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic"># ('d1003', datetime.datetime(2018, 10, 3, 14, 38, 5, 500000), 11.800000190734863, 221, 0.2800000011920929, 'california.losangeles', 2)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic"># ('d1003', datetime.datetime(2018, 10, 3, 14, 38, 16, 600000), 13.399999618530273, 223, 0.28999999165534973, 'california.losangeles', 2)</span><br/></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewbox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewbox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/></svg></span></button></div></div></div> <p>一次获取所有查询结果,并把每一行转化为一个字典返回。</p> <div class="language-py codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-py codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token keyword" style="color:#00009f">def</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">fetch_all_demo</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">conn</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"> taos</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">TaosConnection</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> result</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"> taos</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">TaosResult </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> conn</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">query</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"SELECT ts, current FROM meters LIMIT 2"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> rows </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> result</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">fetch_all_into_dict</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">print</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"row count:"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> result</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">row_count</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">print</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"===============all data==================="</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">print</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">rows</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic"># row count: 2</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic"># ===============all data===================</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic"># [{'ts': datetime.datetime(2018, 10, 3, 14, 38, 5, 500000), 'current': 11.800000190734863},</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic"># {'ts': datetime.datetime(2018, 10, 3, 14, 38, 16, 600000), 'current': 13.399999618530273}]</span><br/></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewbox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewbox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/></svg></span></button></div></div></div> <p><a href="https://github.com/taosdata/TDengine/blob/main/docs/examples/python/query_example.py" target="_blank" rel="noopener noreferrer">查看源码</a></p></div><div role="tabpanel" class="tabItem_Ymn6" hidden=""><div class="language-go codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-go codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token keyword" style="color:#00009f">package</span><span class="token plain"> main</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token keyword" style="color:#00009f">import</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"database/sql"</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"log"</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token string" style="color:#e3116c">"time"</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">_</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"github.com/taosdata/driver-go/v3/taosRestful"</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token keyword" style="color:#00009f">func</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">main</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">var</span><span class="token plain"> taosDSN </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"root:taosdata@http(localhost:6041)/power"</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> taos</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> err </span><span class="token operator" style="color:#393A34">:=</span><span class="token plain"> sql</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">Open</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"taosRestful"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> taosDSN</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">if</span><span class="token plain"> err </span><span class="token operator" style="color:#393A34">!=</span><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">nil</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> log</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">Fatalln</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"failed to connect TDengine, err:"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> err</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">defer</span><span class="token plain"> taos</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">Close</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> rows</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> err </span><span class="token operator" style="color:#393A34">:=</span><span class="token plain"> taos</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">Query</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"SELECT ts, current FROM meters LIMIT 2"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">if</span><span class="token plain"> err </span><span class="token operator" style="color:#393A34">!=</span><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">nil</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> log</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">Fatalln</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"failed to select from table, err:"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> err</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">defer</span><span class="token plain"> rows</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">Close</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">for</span><span class="token plain"> rows</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">Next</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">var</span><span class="token plain"> r </span><span class="token keyword" style="color:#00009f">struct</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> ts time</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">Time</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> current </span><span class="token builtin">float32</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> err </span><span class="token operator" style="color:#393A34">:=</span><span class="token plain"> rows</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">Scan</span><span class="token punctuation" style="color:#393A34">(</span><span class="token operator" style="color:#393A34">&</span><span class="token plain">r</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">ts</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">&</span><span class="token plain">r</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">current</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">if</span><span class="token plain"> err </span><span class="token operator" style="color:#393A34">!=</span><span class="token plain"> </span><span class="token boolean" style="color:#36acaa">nil</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> log</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">Fatalln</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"scan error:\n"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> err</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">return</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> log</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">Println</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">r</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">ts</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> r</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">current</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewbox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewbox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/></svg></span></button></div></div></div> <p><a href="https://github.com/taosdata/TDengine/blob/main/docs/examples/go/query/sync/main.go" target="_blank" rel="noopener noreferrer">查看源码</a></p></div><div role="tabpanel" class="tabItem_Ymn6" hidden=""><div class="language-rust codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-rust codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token keyword" style="color:#00009f">use</span><span class="token plain"> </span><span class="token namespace" style="opacity:0.7">taos</span><span class="token namespace punctuation" style="opacity:0.7;color:#393A34">::</span><span class="token namespace" style="opacity:0.7">sync</span><span class="token namespace punctuation" style="opacity:0.7;color:#393A34">::</span><span class="token operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token keyword" style="color:#00009f">fn</span><span class="token plain"> </span><span class="token function-definition function" style="color:#d73a49">main</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">-></span><span class="token plain"> </span><span class="token namespace" style="opacity:0.7">anyhow</span><span class="token namespace punctuation" style="opacity:0.7;color:#393A34">::</span><span class="token class-name">Result</span><span class="token operator" style="color:#393A34"><</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token operator" style="color:#393A34">></span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">let</span><span class="token plain"> taos </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token class-name">TaosBuilder</span><span class="token punctuation" style="color:#393A34">::</span><span class="token function" style="color:#d73a49">from_dsn</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"ws:///power"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token operator" style="color:#393A34">?</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">build</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token operator" style="color:#393A34">?</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">let</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">mut</span><span class="token plain"> result </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> taos</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">query</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"SELECT ts, current FROM meters LIMIT 2"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token operator" style="color:#393A34">?</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token comment" style="color:#999988;font-style:italic">// print column names</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">let</span><span class="token plain"> meta </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> result</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">fields</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token macro property" style="color:#36acaa">println!</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"{}"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> meta</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">iter</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">map</span><span class="token punctuation" style="color:#393A34">(</span><span class="token closure-params closure-punctuation punctuation" style="color:#393A34">|</span><span class="token closure-params">field</span><span class="token closure-params closure-punctuation punctuation" style="color:#393A34">|</span><span class="token plain"> field</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">name</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">join</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"\t"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token comment" style="color:#999988;font-style:italic">// print rows</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">let</span><span class="token plain"> rows </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> result</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">rows</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">for</span><span class="token plain"> row </span><span class="token keyword" style="color:#00009f">in</span><span class="token plain"> rows </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">let</span><span class="token plain"> row </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> row</span><span class="token operator" style="color:#393A34">?</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">for</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">_name</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> value</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">in</span><span class="token plain"> row </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token macro property" style="color:#36acaa">print!</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"{}\t"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> value</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token macro property" style="color:#36acaa">println!</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token class-name">Ok</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic">// output(suppose you are in +8 timezone):</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic">// ts current</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic">// 2018-10-03T14:38:05+08:00 10.3</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic">// 2018-10-03T14:38:15+08:00 12.6</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewbox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewbox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/></svg></span></button></div></div></div> <p><a href="https://github.com/taosdata/TDengine/blob/main/docs/examples/rust/restexample/examples/query_example.rs" target="_blank" rel="noopener noreferrer">查看源码</a></p></div><div role="tabpanel" class="tabItem_Ymn6" hidden=""><div class="language-js codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-js codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token keyword" style="color:#00009f">const</span><span class="token plain"> taos </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">require</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"@tdengine/client"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token keyword" style="color:#00009f">const</span><span class="token plain"> conn </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> taos</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">connect</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">host</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"localhost"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token literal-property property" style="color:#36acaa">database</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"power"</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token keyword" style="color:#00009f">const</span><span class="token plain"> cursor </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> conn</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">cursor</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token keyword" style="color:#00009f">const</span><span class="token plain"> query </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> cursor</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">query</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"SELECT ts, current FROM meters LIMIT 2"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain">query</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">execute</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">then</span><span class="token punctuation" style="color:#393A34">(</span><span class="token keyword" style="color:#00009f">function</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token parameter">result</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> result</span><span class="token punctuation" style="color:#393A34">.</span><span class="token method function property-access" style="color:#d73a49">pretty</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic">// output:</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic">// Successfully connected to TDengine</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic">// ts | current |</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic">// =======================================================</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic">// 2018-10-03 14:38:05.000 | 10.3 |</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic">// 2018-10-03 14:38:15.000 | 12.6 |</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewbox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewbox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/></svg></span></button></div></div></div> <p><a href="https://github.com/taosdata/TDengine/blob/main/docs/examples/node/nativeexample/query_example.js" target="_blank" rel="noopener noreferrer">查看源码</a></p></div><div role="tabpanel" class="tabItem_Ymn6" hidden=""><div class="language-csharp codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-csharp codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token keyword" style="color:#00009f">using</span><span class="token plain"> </span><span class="token namespace" style="opacity:0.7">System</span><span class="token namespace punctuation" style="opacity:0.7;color:#393A34">.</span><span class="token namespace" style="opacity:0.7">Text</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token keyword" style="color:#00009f">using</span><span class="token plain"> </span><span class="token namespace" style="opacity:0.7">TDengine</span><span class="token namespace punctuation" style="opacity:0.7;color:#393A34">.</span><span class="token namespace" style="opacity:0.7">Driver</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token keyword" style="color:#00009f">using</span><span class="token plain"> </span><span class="token namespace" style="opacity:0.7">TDengine</span><span class="token namespace punctuation" style="opacity:0.7;color:#393A34">.</span><span class="token namespace" style="opacity:0.7">Driver</span><span class="token namespace punctuation" style="opacity:0.7;color:#393A34">.</span><span class="token namespace" style="opacity:0.7">Client</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token keyword" style="color:#00009f">namespace</span><span class="token plain"> </span><span class="token namespace" style="opacity:0.7">TDengineExample</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">internal</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">class</span><span class="token plain"> </span><span class="token class-name">QueryExample</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">public</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">static</span><span class="token plain"> </span><span class="token return-type class-name keyword" style="color:#00009f">void</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">Main</span><span class="token punctuation" style="color:#393A34">(</span><span class="token class-name keyword" style="color:#00009f">string</span><span class="token class-name punctuation" style="color:#393A34">[</span><span class="token class-name punctuation" style="color:#393A34">]</span><span class="token plain"> args</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token class-name keyword" style="color:#00009f">var</span><span class="token plain"> builder </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">new</span><span class="token plain"> </span><span class="token constructor-invocation class-name">ConnectionStringBuilder</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"host=localhost;port=6030;username=root;password=taosdata"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">using</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token class-name keyword" style="color:#00009f">var</span><span class="token plain"> client </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> DbDriver</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">Open</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">builder</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">try</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> client</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">Exec</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"use power"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token class-name keyword" style="color:#00009f">string</span><span class="token plain"> query </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"SELECT * FROM meters"</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">using</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token class-name keyword" style="color:#00009f">var</span><span class="token plain"> rows </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> client</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">Query</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">query</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">while</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">rows</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">Read</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> Console</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">WriteLine</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token interpolation-string string" style="color:#e3116c">$"</span><span class="token interpolation-string interpolation punctuation" style="color:#393A34">{</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">(</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">(</span><span class="token interpolation-string interpolation expression language-csharp">DateTime</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">)</span><span class="token interpolation-string interpolation expression language-csharp">rows</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">.</span><span class="token interpolation-string interpolation expression language-csharp function" style="color:#d73a49">GetValue</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">(</span><span class="token interpolation-string interpolation expression language-csharp number" style="color:#36acaa">0</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">)</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">)</span><span class="token interpolation-string interpolation format-string punctuation" style="color:#393A34">:</span><span class="token interpolation-string interpolation format-string">yyyy-MM-dd HH:mm:ss.fff</span><span class="token interpolation-string interpolation punctuation" style="color:#393A34">}</span><span class="token interpolation-string string" style="color:#e3116c">, </span><span class="token interpolation-string interpolation punctuation" style="color:#393A34">{</span><span class="token interpolation-string interpolation expression language-csharp">rows</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">.</span><span class="token interpolation-string interpolation expression language-csharp function" style="color:#d73a49">GetValue</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">(</span><span class="token interpolation-string interpolation expression language-csharp number" style="color:#36acaa">1</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">)</span><span class="token interpolation-string interpolation punctuation" style="color:#393A34">}</span><span class="token interpolation-string string" style="color:#e3116c">, </span><span class="token interpolation-string interpolation punctuation" style="color:#393A34">{</span><span class="token interpolation-string interpolation expression language-csharp">rows</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">.</span><span class="token interpolation-string interpolation expression language-csharp function" style="color:#d73a49">GetValue</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">(</span><span class="token interpolation-string interpolation expression language-csharp number" style="color:#36acaa">2</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">)</span><span class="token interpolation-string interpolation punctuation" style="color:#393A34">}</span><span class="token interpolation-string string" style="color:#e3116c">, </span><span class="token interpolation-string interpolation punctuation" style="color:#393A34">{</span><span class="token interpolation-string interpolation expression language-csharp">rows</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">.</span><span class="token interpolation-string interpolation expression language-csharp function" style="color:#d73a49">GetValue</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">(</span><span class="token interpolation-string interpolation expression language-csharp number" style="color:#36acaa">3</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">)</span><span class="token interpolation-string interpolation punctuation" style="color:#393A34">}</span><span class="token interpolation-string string" style="color:#e3116c">, </span><span class="token interpolation-string interpolation punctuation" style="color:#393A34">{</span><span class="token interpolation-string interpolation expression language-csharp">rows</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">.</span><span class="token interpolation-string interpolation expression language-csharp function" style="color:#d73a49">GetValue</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">(</span><span class="token interpolation-string interpolation expression language-csharp number" style="color:#36acaa">4</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">)</span><span class="token interpolation-string interpolation punctuation" style="color:#393A34">}</span><span class="token interpolation-string string" style="color:#e3116c">, </span><span class="token interpolation-string interpolation punctuation" style="color:#393A34">{</span><span class="token interpolation-string interpolation expression language-csharp">Encoding</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">.</span><span class="token interpolation-string interpolation expression language-csharp">UTF8</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">.</span><span class="token interpolation-string interpolation expression language-csharp function" style="color:#d73a49">GetString</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">(</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">(</span><span class="token interpolation-string interpolation expression language-csharp keyword" style="color:#00009f">byte</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">[</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">]</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">)</span><span class="token interpolation-string interpolation expression language-csharp">rows</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">.</span><span class="token interpolation-string interpolation expression language-csharp function" style="color:#d73a49">GetValue</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">(</span><span class="token interpolation-string interpolation expression language-csharp number" style="color:#36acaa">5</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">)</span><span class="token interpolation-string interpolation expression language-csharp punctuation" style="color:#393A34">)</span><span class="token interpolation-string interpolation punctuation" style="color:#393A34">}</span><span class="token interpolation-string string" style="color:#e3116c">"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">catch</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token class-name">Exception</span><span class="token plain"> e</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> Console</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">WriteLine</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">e</span><span class="token punctuation" style="color:#393A34">.</span><span class="token function" style="color:#d73a49">ToString</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">throw</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token punctuation" style="color:#393A34">}</span><br/></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewbox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewbox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/></svg></span></button></div></div></div> <p><a href="https://github.com/taosdata/TDengine/blob/main/docs/examples/csharp/query/Program.cs" target="_blank" rel="noopener noreferrer">查看源码</a></p></div><div role="tabpanel" class="tabItem_Ymn6" hidden=""><div class="language-c codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-c codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token comment" style="color:#999988;font-style:italic">// compile with:</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic">// gcc -o query_example query_example.c -ltaos</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token macro property directive-hash" style="color:#36acaa">#</span><span class="token macro property directive keyword" style="color:#00009f">include</span><span class="token macro property" style="color:#36acaa"> </span><span class="token macro property string" style="color:#e3116c"><inttypes.h></span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token macro property directive-hash" style="color:#36acaa">#</span><span class="token macro property directive keyword" style="color:#00009f">include</span><span class="token macro property" style="color:#36acaa"> </span><span class="token macro property string" style="color:#e3116c"><stdio.h></span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token macro property directive-hash" style="color:#36acaa">#</span><span class="token macro property directive keyword" style="color:#00009f">include</span><span class="token macro property" style="color:#36acaa"> </span><span class="token macro property string" style="color:#e3116c"><stdlib.h></span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token macro property directive-hash" style="color:#36acaa">#</span><span class="token macro property directive keyword" style="color:#00009f">include</span><span class="token macro property" style="color:#36acaa"> </span><span class="token macro property string" style="color:#e3116c"><string.h></span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token macro property directive-hash" style="color:#36acaa">#</span><span class="token macro property directive keyword" style="color:#00009f">include</span><span class="token macro property" style="color:#36acaa"> </span><span class="token macro property string" style="color:#e3116c"><taos.h></span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token keyword" style="color:#00009f">typedef</span><span class="token plain"> </span><span class="token class-name">uint16_t</span><span class="token plain"> VarDataLenT</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token macro property directive-hash" style="color:#36acaa">#</span><span class="token macro property directive keyword" style="color:#00009f">define</span><span class="token macro property" style="color:#36acaa"> </span><span class="token macro property macro-name" style="color:#36acaa">TSDB_NCHAR_SIZE</span><span class="token macro property" style="color:#36acaa"> </span><span class="token macro property expression keyword" style="color:#00009f">sizeof</span><span class="token macro property expression punctuation" style="color:#393A34">(</span><span class="token macro property expression class-name" style="color:#36acaa">int32_t</span><span class="token macro property expression punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token macro property directive-hash" style="color:#36acaa">#</span><span class="token macro property directive keyword" style="color:#00009f">define</span><span class="token macro property" style="color:#36acaa"> </span><span class="token macro property macro-name" style="color:#36acaa">VARSTR_HEADER_SIZE</span><span class="token macro property" style="color:#36acaa"> </span><span class="token macro property expression keyword" style="color:#00009f">sizeof</span><span class="token macro property expression punctuation" style="color:#393A34">(</span><span class="token macro property expression" style="color:#36acaa">VarDataLenT</span><span class="token macro property expression punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token macro property directive-hash" style="color:#36acaa">#</span><span class="token macro property directive keyword" style="color:#00009f">define</span><span class="token macro property" style="color:#36acaa"> </span><span class="token macro property macro-name function" style="color:#d73a49">GET_FLOAT_VAL</span><span class="token macro property expression punctuation" style="color:#393A34">(</span><span class="token macro property expression" style="color:#36acaa">x</span><span class="token macro property expression punctuation" style="color:#393A34">)</span><span class="token macro property expression" style="color:#36acaa"> </span><span class="token macro property expression punctuation" style="color:#393A34">(</span><span class="token macro property expression operator" style="color:#393A34">*</span><span class="token macro property expression punctuation" style="color:#393A34">(</span><span class="token macro property expression keyword" style="color:#00009f">float</span><span class="token macro property expression" style="color:#36acaa"> </span><span class="token macro property expression operator" style="color:#393A34">*</span><span class="token macro property expression punctuation" style="color:#393A34">)</span><span class="token macro property expression punctuation" style="color:#393A34">(</span><span class="token macro property expression" style="color:#36acaa">x</span><span class="token macro property expression punctuation" style="color:#393A34">)</span><span class="token macro property expression punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token macro property directive-hash" style="color:#36acaa">#</span><span class="token macro property directive keyword" style="color:#00009f">define</span><span class="token macro property" style="color:#36acaa"> </span><span class="token macro property macro-name function" style="color:#d73a49">GET_DOUBLE_VAL</span><span class="token macro property expression punctuation" style="color:#393A34">(</span><span class="token macro property expression" style="color:#36acaa">x</span><span class="token macro property expression punctuation" style="color:#393A34">)</span><span class="token macro property expression" style="color:#36acaa"> </span><span class="token macro property expression punctuation" style="color:#393A34">(</span><span class="token macro property expression operator" style="color:#393A34">*</span><span class="token macro property expression punctuation" style="color:#393A34">(</span><span class="token macro property expression keyword" style="color:#00009f">double</span><span class="token macro property expression" style="color:#36acaa"> </span><span class="token macro property expression operator" style="color:#393A34">*</span><span class="token macro property expression punctuation" style="color:#393A34">)</span><span class="token macro property expression punctuation" style="color:#393A34">(</span><span class="token macro property expression" style="color:#36acaa">x</span><span class="token macro property expression punctuation" style="color:#393A34">)</span><span class="token macro property expression punctuation" style="color:#393A34">)</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token macro property directive-hash" style="color:#36acaa">#</span><span class="token macro property directive keyword" style="color:#00009f">define</span><span class="token macro property" style="color:#36acaa"> </span><span class="token macro property macro-name function" style="color:#d73a49">varDataLen</span><span class="token macro property expression punctuation" style="color:#393A34">(</span><span class="token macro property expression" style="color:#36acaa">v</span><span class="token macro property expression punctuation" style="color:#393A34">)</span><span class="token macro property expression" style="color:#36acaa"> </span><span class="token macro property expression punctuation" style="color:#393A34">(</span><span class="token macro property expression punctuation" style="color:#393A34">(</span><span class="token macro property expression" style="color:#36acaa">VarDataLenT </span><span class="token macro property expression operator" style="color:#393A34">*</span><span class="token macro property expression punctuation" style="color:#393A34">)</span><span class="token macro property expression punctuation" style="color:#393A34">(</span><span class="token macro property expression" style="color:#36acaa">v</span><span class="token macro property expression punctuation" style="color:#393A34">)</span><span class="token macro property expression punctuation" style="color:#393A34">)</span><span class="token macro property expression punctuation" style="color:#393A34">[</span><span class="token macro property expression number" style="color:#36acaa">0</span><span class="token macro property expression punctuation" style="color:#393A34">]</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token keyword" style="color:#00009f">int</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">printRow</span><span class="token punctuation" style="color:#393A34">(</span><span class="token keyword" style="color:#00009f">char</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token plain">str</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> TAOS_ROW row</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> TAOS_FIELD </span><span class="token operator" style="color:#393A34">*</span><span class="token plain">fields</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">int</span><span class="token plain"> numFields</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">int</span><span class="token plain"> len </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">0</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">char</span><span class="token plain"> split </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token char">' '</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">for</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token keyword" style="color:#00009f">int</span><span class="token plain"> i </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">0</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"> i </span><span class="token operator" style="color:#393A34"><</span><span class="token plain"> numFields</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">++</span><span class="token plain">i</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">if</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">i </span><span class="token operator" style="color:#393A34">></span><span class="token plain"> </span><span class="token number" style="color:#36acaa">0</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> str</span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">len</span><span class="token operator" style="color:#393A34">++</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> split</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">if</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">row</span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">i</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">==</span><span class="token plain"> </span><span class="token constant" style="color:#36acaa">NULL</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> len </span><span class="token operator" style="color:#393A34">+=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">sprintf</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">str </span><span class="token operator" style="color:#393A34">+</span><span class="token plain"> len</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"%s"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"NULL"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">continue</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">switch</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">fields</span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">i</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">type</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">case</span><span class="token plain"> TSDB_DATA_TYPE_TINYINT</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> len </span><span class="token operator" style="color:#393A34">+=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">sprintf</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">str </span><span class="token operator" style="color:#393A34">+</span><span class="token plain"> len</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"%d"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">(</span><span class="token class-name">int8_t</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain">row</span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">i</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">break</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">case</span><span class="token plain"> TSDB_DATA_TYPE_UTINYINT</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> len </span><span class="token operator" style="color:#393A34">+=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">sprintf</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">str </span><span class="token operator" style="color:#393A34">+</span><span class="token plain"> len</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"%u"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">(</span><span class="token class-name">uint8_t</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain">row</span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">i</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">break</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">case</span><span class="token plain"> TSDB_DATA_TYPE_SMALLINT</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> len </span><span class="token operator" style="color:#393A34">+=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">sprintf</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">str </span><span class="token operator" style="color:#393A34">+</span><span class="token plain"> len</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"%d"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">(</span><span class="token class-name">int16_t</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain">row</span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">i</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">break</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">case</span><span class="token plain"> TSDB_DATA_TYPE_USMALLINT</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> len </span><span class="token operator" style="color:#393A34">+=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">sprintf</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">str </span><span class="token operator" style="color:#393A34">+</span><span class="token plain"> len</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"%u"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">(</span><span class="token class-name">uint16_t</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain">row</span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">i</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">break</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">case</span><span class="token plain"> TSDB_DATA_TYPE_INT</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> len </span><span class="token operator" style="color:#393A34">+=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">sprintf</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">str </span><span class="token operator" style="color:#393A34">+</span><span class="token plain"> len</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"%d"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">(</span><span class="token class-name">int32_t</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain">row</span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">i</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">break</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">case</span><span class="token plain"> TSDB_DATA_TYPE_UINT</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> len </span><span class="token operator" style="color:#393A34">+=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">sprintf</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">str </span><span class="token operator" style="color:#393A34">+</span><span class="token plain"> len</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"%u"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">(</span><span class="token class-name">uint32_t</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain">row</span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">i</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">break</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">case</span><span class="token plain"> TSDB_DATA_TYPE_BIGINT</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> len </span><span class="token operator" style="color:#393A34">+=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">sprintf</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">str </span><span class="token operator" style="color:#393A34">+</span><span class="token plain"> len</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"%"</span><span class="token plain"> PRId64</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">(</span><span class="token class-name">int64_t</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain">row</span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">i</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">break</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">case</span><span class="token plain"> TSDB_DATA_TYPE_UBIGINT</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> len </span><span class="token operator" style="color:#393A34">+=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">sprintf</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">str </span><span class="token operator" style="color:#393A34">+</span><span class="token plain"> len</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"%"</span><span class="token plain"> PRIu64</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">(</span><span class="token class-name">uint64_t</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain">row</span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">i</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">break</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">case</span><span class="token plain"> TSDB_DATA_TYPE_FLOAT</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">float</span><span class="token plain"> fv </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">0</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> fv </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">GET_FLOAT_VAL</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">row</span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">i</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> len </span><span class="token operator" style="color:#393A34">+=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">sprintf</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">str </span><span class="token operator" style="color:#393A34">+</span><span class="token plain"> len</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"%f"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> fv</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">break</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">case</span><span class="token plain"> TSDB_DATA_TYPE_DOUBLE</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">double</span><span class="token plain"> dv </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">0</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> dv </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">GET_DOUBLE_VAL</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">row</span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">i</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> len </span><span class="token operator" style="color:#393A34">+=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">sprintf</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">str </span><span class="token operator" style="color:#393A34">+</span><span class="token plain"> len</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"%lf"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> dv</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">break</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">case</span><span class="token plain"> TSDB_DATA_TYPE_BINARY</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">case</span><span class="token plain"> TSDB_DATA_TYPE_VARBINARY</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">case</span><span class="token plain"> TSDB_DATA_TYPE_NCHAR</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">case</span><span class="token plain"> TSDB_DATA_TYPE_GEOMETRY</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token class-name">int32_t</span><span class="token plain"> charLen </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">varDataLen</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">(</span><span class="token keyword" style="color:#00009f">char</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain">row</span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">i</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">-</span><span class="token plain"> VARSTR_HEADER_SIZE</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">memcpy</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">str </span><span class="token operator" style="color:#393A34">+</span><span class="token plain"> len</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> row</span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">i</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> charLen</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> len </span><span class="token operator" style="color:#393A34">+=</span><span class="token plain"> charLen</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">break</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">case</span><span class="token plain"> TSDB_DATA_TYPE_TIMESTAMP</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> len </span><span class="token operator" style="color:#393A34">+=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">sprintf</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">str </span><span class="token operator" style="color:#393A34">+</span><span class="token plain"> len</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"%"</span><span class="token plain"> PRId64</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">(</span><span class="token class-name">int64_t</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain">row</span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">i</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">break</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">case</span><span class="token plain"> TSDB_DATA_TYPE_BOOL</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> len </span><span class="token operator" style="color:#393A34">+=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">sprintf</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">str </span><span class="token operator" style="color:#393A34">+</span><span class="token plain"> len</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"%d"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">(</span><span class="token class-name">int8_t</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain">row</span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">i</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">default</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">break</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">return</span><span class="token plain"> len</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic">/**</span><br/></span><span class="token-line" style="color:#393A34"><span class="token comment" style="color:#999988;font-style:italic"> * @brief print column name and values of each row</span><br/></span><span class="token-line" style="color:#393A34"><span class="token comment" style="color:#999988;font-style:italic"> *</span><br/></span><span class="token-line" style="color:#393A34"><span class="token comment" style="color:#999988;font-style:italic"> * @param res</span><br/></span><span class="token-line" style="color:#393A34"><span class="token comment" style="color:#999988;font-style:italic"> * @return int</span><br/></span><span class="token-line" style="color:#393A34"><span class="token comment" style="color:#999988;font-style:italic"> */</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token keyword" style="color:#00009f">static</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">int</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">printResult</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">TAOS_RES </span><span class="token operator" style="color:#393A34">*</span><span class="token plain">res</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">int</span><span class="token plain"> numFields </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">taos_num_fields</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">res</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> TAOS_FIELD </span><span class="token operator" style="color:#393A34">*</span><span class="token plain">fields </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">taos_fetch_fields</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">res</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">char</span><span class="token plain"> header</span><span class="token punctuation" style="color:#393A34">[</span><span class="token number" style="color:#36acaa">256</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token number" style="color:#36acaa">0</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">int</span><span class="token plain"> len </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">0</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">for</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token keyword" style="color:#00009f">int</span><span class="token plain"> i </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">0</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"> i </span><span class="token operator" style="color:#393A34"><</span><span class="token plain"> numFields</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">++</span><span class="token plain">i</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> len </span><span class="token operator" style="color:#393A34">+=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">sprintf</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">header </span><span class="token operator" style="color:#393A34">+</span><span class="token plain"> len</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"%s "</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> fields</span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain">i</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">name</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">puts</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">header</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> TAOS_ROW row </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token constant" style="color:#36acaa">NULL</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">while</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">row </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">taos_fetch_row</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">res</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">char</span><span class="token plain"> temp</span><span class="token punctuation" style="color:#393A34">[</span><span class="token number" style="color:#36acaa">256</span><span class="token punctuation" style="color:#393A34">]</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token number" style="color:#36acaa">0</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">printRow</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">temp</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> row</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> fields</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> numFields</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">puts</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">temp</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token keyword" style="color:#00009f">int</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">main</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> TAOS </span><span class="token operator" style="color:#393A34">*</span><span class="token plain">taos </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">taos_connect</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"localhost"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"root"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"taosdata"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"power"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">6030</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">if</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">taos </span><span class="token operator" style="color:#393A34">==</span><span class="token plain"> </span><span class="token constant" style="color:#36acaa">NULL</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">puts</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"failed to connect to server"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">exit</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">EXIT_FAILURE</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> TAOS_RES </span><span class="token operator" style="color:#393A34">*</span><span class="token plain">res </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">taos_query</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">taos</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"SELECT * FROM meters LIMIT 2"</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token keyword" style="color:#00009f">if</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token function" style="color:#d73a49">taos_errno</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">res</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">!=</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">0</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">printf</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">"failed to execute taos_query. error: %s\n"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">taos_errstr</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">res</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">exit</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">EXIT_FAILURE</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">printResult</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">res</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">taos_free_result</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">res</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">taos_close</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">taos</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">taos_cleanup</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic">// output:</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic">// ts current voltage phase location groupid </span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic">// 1648432611249 10.300000 219 0.310000 California.SanFrancisco 2</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token comment" style="color:#999988;font-style:italic">// 1648432611749 12.600000 218 0.330000 California.SanFrancisco 2</span><br/></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewbox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewbox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/></svg></span></button></div></div></div> <p><a href="https://github.com/taosdata/TDengine/blob/main/docs/examples/c/query_example.c" target="_blank" rel="noopener noreferrer">查看源码</a></p></div><div role="tabpanel" class="tabItem_Ymn6" hidden=""><div class="language-go codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-go codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token operator" style="color:#393A34"><</span><span class="token plain">?php</span><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain">use TDengine\Connection</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain">use TDengine\Exception\TDengineException</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain">try </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token comment" style="color:#999988;font-style:italic">// instantiate</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> $host </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token char">'localhost'</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> $port </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">6030</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> $username </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token char">'root'</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> $password </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token char">'taosdata'</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> $dbname </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token char">'power'</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> $connection </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token builtin">new</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">Connection</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">$host</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> $port</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> $username</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> $password</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> $dbname</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token comment" style="color:#999988;font-style:italic">// connect</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> $connection</span><span class="token operator" style="color:#393A34">-</span><span class="token operator" style="color:#393A34">></span><span class="token function" style="color:#d73a49">connect</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> $resource </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> $connection</span><span class="token operator" style="color:#393A34">-</span><span class="token operator" style="color:#393A34">></span><span class="token function" style="color:#d73a49">query</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">'SELECT ts</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> current FROM meters LIMIT </span><span class="token number" style="color:#36acaa">2</span><span class="token plain">'</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token function" style="color:#d73a49">var_dump</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">$resource</span><span class="token operator" style="color:#393A34">-</span><span class="token operator" style="color:#393A34">></span><span class="token function" style="color:#d73a49">fetch</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"> catch </span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">TDengineException $e</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> </span><span class="token comment" style="color:#999988;font-style:italic">// throw exception</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"> throw $e</span><span class="token punctuation" style="color:#393A34">;</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain"/><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"/><br/></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"/><br/></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewbox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewbox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"/></svg></span></button></div></div></div> <li>无论是使用 REST 连接还是原生连接的连接器,以上示例代码都能正常工作。</li> <li>唯一需要注意的是:由于 REST 接口无状态, 不能使用 <code>use db</code> 语句来切换数据库。除了在 REST 参数中指定数据库以外也可以在 SQL 语句中使用 <db_name>.<table_name> 来指定数据库。</li> <h3 class="anchor anchorWithHideOnScrollNavbar_WYt5" id="异步查询">异步查询<a href="#异步查询" class="hash-link" aria-label="Direct link to 异步查询" title="Direct link to 异步查询"></a></h3> <p>除同步查询 API 之外,TDengine 还提供性能更高的异步调用 API 处理数据插入、查询操作。在软硬件环境相同的情况下,异步 API 处理数据插入的速度比同步 API 快 2-4 倍。异步 API 采用非阻塞式的调用方式,在系统真正完成某个具体数据库操作前,立即返回。调用的线程可以去处理其他工作,从而可以提升整个应用的性能。异步 API 在网络延迟严重的情况下,优点尤为突出。</p> <p>需要注意的是,只有使用原生连接的连接器,才能使用异步查询功能。</p>
推荐文章
笑点低的人字拖
·
济南大学2024年硕士研究生复试名单_教育屋
1 月前
风流倜傥的木瓜
·
2024年西安新房房价走势图,2024西安楼盘均价,西安新房价格趋势查询-安居客
2 月前
年轻有为的香烟
·
刑事检察工作白皮书(2023)_中华人民共和国最高人民检察院
2 月前
强悍的台灯
·
中共八大以来的历届中央政治局常委_改革大数据服务平台
3 月前
强悍的太阳
·
June 2021 - US Military Places a Bet on LEO for Space Security | Via Satellite
5 月前