Skip to main content

query(sql, options?)

Execute a SQL query against the oleander lake using DuckDB. Returns structured results with columns, types, and rows.
const result = await client.query(
  "SELECT * FROM public.iris_dataset LIMIT 10"
);

const columns = result.results?.columns;   // ["sepal_length", "sepal_width", ...]
const rows = result.results?.rows;         // [[5.1, 3.5, ...], ...]
const count = result.row_count;            // 10
const elapsed = result.execution_time;     // "42ms"

Parameters

sql
string
required
The SQL query to execute. Supports all DuckDB SQL syntax.
options.save
boolean
default:"false"
When true, persists query results as a table. The table name is returned in saved_table_name.

Saving results

Use save: true to persist query results as a table for later use.
const result = await client.query(
  "SELECT * FROM public.iris_dataset LIMIT 10",
  { save: true }
);

if (result.saved_table_name) {
  // Run a follow-up query against the saved table
  const followUp = await client.query(
    `SELECT avg(sepal_length) FROM ${result.saved_table_name}`
  );
}

Iterating over results

const result = await client.query("SELECT name, score FROM public.rankings");

const { columns, rows } = result.results!;
const nameIdx = columns.indexOf("name");
const scoreIdx = columns.indexOf("score");

for (const row of rows) {
  const name = row[nameIdx] as string;
  const score = row[scoreIdx] as number;
  // process each record ...
}

Return type: LakeQueryResult

FieldTypeDescription
successbooleanWhether the query executed successfully
resultsobjectQuery results with columns, column_types, and rows
row_countnumberNumber of rows returned
execution_timestringQuery execution time (e.g., "42ms")
saved_table_namestringTable name if save: true was used
querystringThe original SQL query