Insert data

This page shows how to insert data into QuestDB using different programming languages or tools.

First things first#

Make sure you have QuestDB running and accessible, you can do so from Docker, the binaries or Homebrew for macOS users.

REST API#

You can query data using the REST API, this will work with a very wide range of libraries and tools. The REST API is accessible on port 9000.

/imp endpoint#

Using the /imp endpoint will allow you to import a CSV file directly.

curl -F data=@data.csv http://localhost:9000/imp

/query endpoint#

Otherwise you can use /query and execute an INSERT statement.

curl -G \
--data-urlencode "query=INSERT INTO trades VALUES('abc', 123456);" \
http://localhost:9000/exec

InfluxDB line protocol#

QuestDB implements the InfluxDB line protocol, this endpoint is accessible on port 9009.

const net = require("net")
const client = new net.Socket()
const HOST = "localhost"
const PORT = 9009
function run() {
client.connect(PORT, HOST, () => {
const rows = [
`test,location=uk temperature=12.4 ${Date.now() * 1e6}`,
`test,location=uk temperature=11.4 ${Date.now() * 1e6}`,
]
rows.forEach((row) => {
client.write(`${row}\n`)
})
client.destroy()
})
client.on("data", function (data) {
console.log("Received: " + data)
})
client.on("close", function () {
console.log("Connection closed")
})
}
run()

Postgres compatibility#

You can query data using the Postgres endpoint that QuestDB exposes. This is accessible via port 8812.

const { Client } = require("pg")
const start = async () => {
try {
const client = new Client({
database: "qdb",
host: "127.0.0.1",
password: "quest",
port: 8812,
user: "admin",
})
await client.connect()
const res = await client.query("INSERT INTO test VALUES($1, $2);", [
"abc",
"123",
])
console.log(res)
await client.end()
} catch (e) {
console.log(e)
}
}
start()

Web Console#

Our Web Console has an import function. You can find out more about this on the dedicated page.