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 for inserting data:
- InfluxDB line protocol (ILP) which provides flexibility, ease of use, and high ingestion rates
- Postgres wire protocol for compatibility with a range of clients or fallback over ILP
- Rest API which can be used for importing datasets from CSV
InfluxDB Line Protocol is the recommended primary ingestion method in QuestDB.
To query ingested data, users should utilize the Web Console and REST API on
9000 or use a Postgres wire client. Methods for querying data are
described on the query data documentation page.
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
other systems implementing the protocol.
This interface is the preferred ingestion method as it provides the following benefits:
- high-throughput ingestion
- robust ingestion from multiple sources into tables with dedicated systems for reducing congestion
- configurable commit-lag for out-of-order data via server configuration settings
For additional details on the message format, see the InfluxDB line protocol guide. Details on ports and authentication can be found on the InfluxDB API reference page, and a guide on the Telegraf agent for collecting and sending metrics to QuestDB via this protocol can be found on the Telegraf guide.
Each line protocol message must be delimited with newline
The timestamp element of InfluxDB line protocol messages is optional and when omitted, the server will automatically assign 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.