• Postgres wire protocol for compatibility with a range of clients
  • which can be queried via HTTP
  • Web Console which provides a code editor for convenience

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

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

  1. package main
  2. import (
  3. "database/sql"
  4. "fmt"
  5. _ "github.com/lib/pq"
  6. )
  7. const (
  8. host = "localhost"
  9. port = 8812
  10. user = "admin"
  11. password = "quest"
  12. dbname = "qdb"
  13. )
  14. func main() {
  15. connStr := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", host, port, user, password, dbname)
  16. db, err := sql.Open("postgres", connStr)
  17. checkErr(err)
  18. defer db.Close()
  19. // Currently, we do not support queries with bind parameters in Go
  20. rows, err := db.Query("SELECT x FROM long_sequence(5);")
  21. checkErr(err)
  22. defer rows.Close()
  23. for rows.Next() {
  24. var num string
  25. err = rows.Scan(&num)
  26. checkErr(err)
  27. fmt.Println(num)
  28. }
  29. err = rows.Err()
  30. checkErr(err)
  31. }
  32. func checkErr(err error) {
  33. if err != nil {
  34. panic(err)
  35. }
  36. }
  1. // compile with
  2. // g++ libpq_example.c -o libpq_example.exe -I pgsql\include -L dev\pgsql\lib
  3. // -std=c++17 -lpthread -lpq
  4. #include <libpq-fe.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. void do_exit(PGconn *conn) {
  8. PQfinish(conn);
  9. exit(1);
  10. }
  11. PGconn *conn = PQconnectdb(
  12. "host=localhost user=admin password=quest port=8812 dbname=testdb");
  13. if (PQstatus(conn) == CONNECTION_BAD) {
  14. fprintf(stderr, "Connection to database failed: %s\n",
  15. do_exit(conn);
  16. }
  17. PGresult *res = PQexec(conn, "SELECT x FROM long_sequence(5);");
  18. if (PQresultStatus(res) != PGRES_TUPLES_OK) {
  19. printf("No data retrieved\n");
  20. PQclear(res);
  21. do_exit(conn);
  22. }
  23. int rows = PQntuples(res);
  24. for (int i = 0; i < rows; i++) {
  25. printf("%s\n", PQgetvalue(res, i, 0));
  26. }
  27. PQclear(res);
  28. PQfinish(conn);
  29. return 0;
  30. }
  1. using Npgsql;
  2. string username = "admin";
  3. string password = "quest";
  4. string database = "qdb";
  5. int port = 8812;
  6. var connectionString = $"host=localhost;port={port};username={username};password={password};
  7. database={database};ServerCompatibilityMode=NoTypeLoading;";
  8. await using NpgsqlConnection connection = new(connectionString);
  9. await connection.OpenAsync();
  10. var sql = "SELECT x FROM long_sequence(5);";
  11. await using NpgsqlCommand command = new (sql, connection);
  12. await using (var reader = await command.ExecuteReaderAsync()) {
  13. while (await reader.ReadAsync())
  14. {
  15. var station = reader.GetString(0);
  16. var height = double.Parse(reader.GetString(1));
  17. var timestamp = reader.GetString(2);
  18. }
  19. }
  1. import psycopg2
  2. try:
  3. connection = psycopg2.connect(user="admin",
  4. password="quest",
  5. host="127.0.0.1",
  6. port="8812",
  7. database="qdb")
  8. cursor = connection.cursor()
  9. postgreSQL_select_Query = "SELECT x FROM long_sequence(5);"
  10. cursor.execute(postgreSQL_select_Query)
  11. print("Selecting rows from test table using cursor.fetchall")
  12. mobile_records = cursor.fetchall()
  13. print("Print each row and it's columns values")
  14. for row in mobile_records:
  15. print("y = ", row[0], "\n")
  16. except (Exception, psycopg2.Error) as error:
  17. print("Error while fetching data from PostgreSQL", error)
  18. #closing database connection.
  19. if (connection):
  20. cursor.close()
  21. print("PostgreSQL connection is closed")

You can query data using the , 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.

<Tabs defaultValue=”curl” values={[ { label: “cURL”, value: “curl” }, { label: “NodeJS”, value: “nodejs” }, { label: “Go”, value: “go” }, ]}>

  1. const fetch = require("node-fetch")
  2. const qs = require("querystring")
  3. const HOST = "http://localhost:9000"
  4. async function run() {
  5. try {
  6. const queryData = {
  7. query: "SELECT x FROM long_sequence(5);",
  8. }
  9. const response = await fetch(`${HOST}/exec?${qs.encode(queryData)}`)
  10. const json = await response.json()
  11. console.log(json)
  12. } catch (error) {
  13. console.log(error)
  14. }
  15. }
  16. run()
  1. package main
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "log"
  6. "net/http"
  7. "net/url"
  8. )
  9. func main() {
  10. u, err := url.Parse("http://localhost:9000")
  11. checkErr(err)
  12. u.Path += "exec"
  13. params := url.Values{}
  14. params.Add("query", "SELECT x FROM long_sequence(5);")
  15. u.RawQuery = params.Encode()
  16. url := fmt.Sprintf("%v", u)
  17. res, err := http.Get(url)
  18. checkErr(err)
  19. defer res.Body.Close()
  20. body, err := ioutil.ReadAll(res.Body)
  21. checkErr(err)
  22. log.Println(string(body))
  23. }
  24. func checkErr(err error) {
  25. if err != nil {
  26. panic(err)
  27. }

Details for inserting data with the Web Console is covered on the page. To query data from the web console, SQL statements can be written in the code editor and executed by clicking RUN.