Skip to content

Query APIs

This page describes how to use query APIs to interact with the database.

Query APIs are a set of APIs created for users to programmatically interact with the database. The following functions are currently supported:

.com_kx_edi.getMeta

This function returns the metadata of the databases.

.com_kx_edi.getMeta[]

The getMeta API returns meta information on APIs defined in the DAPs and aggregation functions in the Aggs for all DAPs and Aggs in the system. Additionally, it returns information on the assemblies, schemas, metadata, and UDAs including their parameters and return values.

Assembly names

If you are using the assembly names from the getMeta[] function for .com_kx_edi.qsql, ensure the "-qe" is removed before invoking .com_kx_edi.qsql.

Returns:

Type Description
any[] Metadata of the databases

Example:

.com_kx_edi.getMeta[]

// List all UDAs
.com_kx_edi.getMeta[][1;`api]

// List all assemblies
.com_kx_edi.getMeta[][1;`assembly]

// List all tables
.com_kx_edi.getMeta[][1;`schema]

For more details, refer to the getMeta documentation.

.com_kx_edi.sql

This function runs an SQL query.

.com_kx_edi.sql[query]

The SQL API allows queries to be distributed/aggregated across multiple DAPs.

Required Parameters:

Name Description Default
Query A string that expresses the query you wish to run Required

Returns:

Type Description
any Result of sql query

Example:

.com_kx_edi.sql["SELECT * FROM table1 LIMIT 10"]

Refer to the SQL documentation for more details.

.com_kx_edi.qsql

This is a QSQL query builder that assembles QSQL queries based on a q expression.

.com_kx_edi.qsql[args]

This API is intended to run on a data access process and execute the command sent in from the client.

The args dictionary should be structured as follows:

args.assembly {string} The assembly name 
args.target   {string} The tier ("rdb", "idb", or "hdb")
args.query    {string} A q expression

Required Parameters:

Name Description Default
args A dictionary that contains the assembly, target, and q query Required

Returns:

Type Description
any Result of q expression

Example:

// List all assemblies
q).com_kx_edi.getMeta[][1;`assembly]
assembly              kxname           tbls           
------------------------------------------------------
example-pkg-qe        trades-db        trades

// The "-qe" must be omitted from the assembly name
q).com_kx_edi.qsql[`assembly`target`query!("example-pkg";"rdb";"select max bid from trades")]

For more information, refer to the QSQL documentation.

.com_kx_edi.queryBuilder

The queryBuilder function uses the GetData API to construct queries.

 .com_kx_edi.queryBuilder[args]

The queryBuilder uses arguments found in GetData API.

The Query Builder is a generic data retrieval API that can be executed against an arbitrary database table. It is intended to run on a Data Access Process and retrieve records from a configured database table using a specified dictionary of parameters, as specified below.

Required Parameters:

Name Description Default
args The list of arguments can be found in the getData parameters Required

Returns:

Type Description
table Result of table query

Example:

.com_kx_edi.queryBuilder[`table`startTS`endTS!("table1";2024.01.01D; 2024.01.02D)]

.com_kx_edi.uda

Use this function to query a UDA.

.com_kx_edi.uda[args;name]

Refer to these example UDAs for more details

The UDA API allows you to directly query a UDA against databases within a package.

Required Parameters:

Name Description Default
args A dictionary of UDA defined parameters. Required
name The name of the UDA including namespace in the form of namespace/udaName, such as example/daAPI Required

Returns:

Type Description
any Result of UDA

Example:

args:`table`column`multiplier`startTS`endTS!(`table1;`column1;10;2024.11.06D;2024.11.21D);
.com_kx_edi.uda[args;"example/daAPI"]