Query data

This page describes how to query data from QuestDB using different programming languages and tools. To query data in a running instance, there are three main methods that can be used:

  1. Web Console which provides a code editor, table schema explorer and a data visualization panel
  2. Rest API which can be queried via HTTP
  3. Postgres wire protocol for compatibility with a range of clients

Prerequisites#

QuestDB must be running and accessible, you can do so from Docker, the binaries or Homebrew for macOS users.

Web Console#

QuestDB ships with an embedded Web Console running by default on port 9000.

Screenshot of the Web Console

To query data from the web console, SQL statements can be written in the code editor and executed by clicking RUN.

Listing tables and querying a table
SHOW TABLES;
SELECT * FROM my_table;
--Note that `SELECT * FROM` is optional
my_table;

Aside from the Code Editor, the Web Console includes a data visualization panel for viewing query results as tables or graphs and an Import tab for uploading datasets as CSV files. For more details on these components and general use of the console, see the Web Console reference page.

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.

More information on the available endpoints alongside possible parameters and usage examples can be found on the REST API reference page.

curl -G \
--data-urlencode "query=SELECT x FROM long_sequence(5);" \
http://localhost:9000/exec

Postgres compatibility#

You can query data using the Postgres endpoint that QuestDB exposes which is accessible by default 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("SELECT x FROM long_sequence(5);")
console.log(res.rows)
await client.end()
} catch (e) {
console.log(e)
}
}
start()