すべてのプロダクト
Search
ドキュメントセンター

Tablestore:SQL 文を実行してデータをクエリする

最終更新日:May 27, 2025

このトピックでは、Tablestore SDK for Node.js を使用して SQL 文を実行し、データをクエリする方法について説明します。

前提条件

パラメーター

パラメーター

説明

query

SQL 文。必要な機能に基づいてこのパラメーターを設定します。

次のサンプルコードは、test_table という名前のテーブル内のすべてのデータをクエリする方法の例を示しています。

const client = require('./client');

const params = {
    query: "select * from test_table",
}

client.sqlQuery(params, function (err, resp) {
    if (err) {
        console.log('sqlQuery error:', err.toString()); // sqlQuery エラー
    } else {
        console.log('sqlQuery success:', resp); // sqlQuery 成功
        console.log(resp.sqlRows.rowCount.toFloat64());
        console.log(resp.sqlRows.columnCount);
        console.log(resp.sqlRows.sqlTableMeta)
        for (let i = 0; i < resp.sqlRows.rowCount.toFloat64(); i++) {
            for (let j = 0; j < resp.sqlRows.columnCount; j++) {
                let data = resp.sqlRows.get(i, j);
                // Process data of the Binary type. // Binary タイプのデータを処理します。
                if (resp.sqlRows.sqlTableMeta.schemas[j].typeName === "BINARY") {
                    let int8Array = data.valueArray();
                    console.log(int8Array);
                }
                // Process data of the Long type. // Long タイプのデータを処理します。
                if (resp.sqlRows.sqlTableMeta.schemas[j].typeName === "LONG") {
                    console.log(data.toFloat64());
                }
                console.log("i:" + i, ", j:" + j + ":" + data);
            }
        }
    }
});

FAQ

参照