This page shows how to insert data into QuestDB using different programming languages and tools. To ingest data to a running instance, there are three main methods that can be used:
- InfluxDB line protocol which provides flexibility, ease of use, and high ingestion rates
- Postgres wire protocol for compatibility with a range of clients
- Rest API which can be used for importing datasets from CSV
QuestDB implements InfluxDB line protocol which is accessible by default on TCP
9009. This allows using QuestDB as a drop-in replacement for InfluxDB and
others implementing the protocol. Configuration settings for ingestion using
this protocol can be set for for
Influx line over TCP
Influx line over UDP.
More information on the InfluxDB line protocol implementation with details on message format, ports, authentication and examples can be found on the InfluxDB API reference page. Additionally, a guide on the Telegraf agent for collecting and sending metrics to QuestDB via this protocol can be found on the Telegraf guide.
The following examples add a timestamp property to each line protocol message. This property is optional and can be omitted to allow the server to automatically assign the the server's system time as the row's timestamp value.
You can query data using the Postgres endpoint
that QuestDB exposes. This is accessible via port
8812 by default. More
information on the Postgres wire protocol implementation with details on
supported features can be found on the
Postgres API reference page.
This example uses naive
Date.now() * 1000 inserts for Timestamp types in
microsecond resolution. For accurate microsecond timestamps, the
node-microtime package can be used
which makes system calls to
tv_usec from C++.
The following example shows how to use parameterized queries and prepared statements using the rust-postgres client.
QuestDB exposes a REST API for compatibility with a wide range of libraries and
tools. The REST API is accessible on port
9000 and has the following
/imp- import data
/exec- execute an SQL statement
More details on the use of these entrypoints can be found on the REST API reference page.
/imp endpoint allows for importing a CSV file directly.
This example imports a CSV file with automatic schema detection.
This example overwrites an existing table, specifies a timestamp format and a designated timestamp column. For more information on the optional parameters for specifying timestamp formats, partitioning and renaming tables, see the REST API documentation.
/exec endpoint can be used to create a table and the
INSERT statement can be used to populate it with values:
Note that these two queries can be combined into a single curl request:
node-fetch package can be installed using
npm i node-fetch.
By default, QuestDB has an embedded Web Console running at http://[server-address]:9000. When running locally, this is accessible at http://localhost:9000. The Web Console can be used to explore table schemas, visualizing query results as tables or graphs, and importing datasets from CSV files. For details on these components, refer to the Web Console reference page.