Skip to main content
The Kinetica Go API is a native Go client for the database: connection setup, sessions, HA failover & fail-back, multi-head routing, retries, records, bulk insertion, SQL clients, and KiFS. Every Kinetica endpoint is a method on the connection, taking a typed request and returning a typed response. The API’s reference documentation is published on pkg.go.dev, where Go module documentation lives, and its source is on GitHub:

Installation

The module requires Go 1.26 or later. Add it to a project with go get:
Then import the client package:
Import
Two further packages hold the KiFS client and the string constants of every request’s & response’s fields:
Supporting Packages

Connecting

A connection is made with Connect, given the URL of a Kinetica database server and the connection options, which carry the credentials. Connect discovers the clusters of the HA ring and the worker ranks of each, and reads the server version; it fails if no server answers.
Each connection is its own server session, and the session temp tables it creates belong to that session; Close drops them. A connection is safe for concurrent use. For connecting over HTTPS, with or without certificate validation, and with an OAuth token, see Connecting via API. For failover across an HA ring, give Connect the head node of each cluster, or let it discover the ring from one.

Using the API

The following walks through the operations of the quick start example, which creates a table, loads it, queries it, and drops it.

Tables & Types

A table’s record type can be defined from a Go struct. Each exported field is a column, named and given column properties by its kinetica tag; a pointer field is nullable.
The type is registered with the database, and a table created from it:
A type can also be built column by column with a TypeBuilder, or read from an existing table with NewTypeFromTable.

Inserting Records

Records of the struct type are inserted in one request with InsertRecordsTyped:

Bulk Loading

For loading many records, a BulkInserter batches them and sends each batch directly to the worker rank that holds it, using distributed ingest. Insert queues a record; Close flushes what is buffered, waits for every batch, and returns the batches that failed, if any.

Querying with SQL

Query runs a SQL query and returns an iterator over its records, which are read from the server a batch at a time. The iterator must be closed, which drops the paging table the query made.
Execute runs any other SQL statement and returns the number of records it affected. The WithParameters form of each takes the values for the ? placeholders in the statement, sent as the query parameters of the request:
SQLParametersValues sends the values as text, which the server converts to the column types; SQLParametersJSON sends typed values, nulls, and slices for several rows. The full SQL feature set is available through these calls; see the SQL section for the language.

Retrieving Records

GetRecordsTyped reads records back into the struct, matching each column to the field of its name. The options take a filter expression and a sort order, among others.

Dropping a Table

Errors

Every call returns a *kinetica.Error, which carries a kind and a message: an API error for a request the server refused, Unauthorized for a rejected login, Connection for a request that got no response, and so on. errors.Is finds a kind anywhere in an error’s chain, and errors.As reaches the error itself:
Error Handling
The kinds, and which of them the client fails over for, are listed in the Go API Reference.

Quick Start Example

The complete program the sections above are drawn from. It takes the database URL and login on the command line: