Skip to content

Query

This section contains details of how to execute queries against tables in KDB.AI.

Selecting the table to query

Each table in KDB.AI has an associated name. In order to perform a query, specify the table in which the relevant data is stored. Using the Python client you can create a table object from the session.

documents = session.table("documents")

Queries

First off you can get the data from the entire table via

documents.query()

Filters

In order to select a subset of the data you can apply filters as documented here these serve as where clasues

documents.query(filter=[("within","createdDate",["2020.07.10D15:00:00.0000", "2021.07.10D15:00:00.0000"]),("<=", "length", 100)])

Processing results

It is possible to return a subset of the columns in the table reducing the amount to data sent back to the client.

documents.query(aggs=[["author"],["context"]])

In addition to returning a subset of the columns the user can return aggregated resuts, group by categorical variables, and sort based on a column name.

documents.query(aggs=[('sumLength','sum','length')], group_by=['author'], sort_by=['sumLength'])