PostgreSQL & PGWire

QuestDB supports the Postgres Wire Protocol (PGWire) for data-in.

For querying and data-out, QuestDB is compatible with PostgreSQL queries.

This means that you can use your favorite PostgreSQL client or driver with QuestDB.

For information querying and data-out, see the Querying & SQL Overview

note

The PostgreSQL storage model is fundamentally different than that of QuestDB.

As a result, some features that exists for Postgres do not exist in QuestDB.

Ingest examples

This example uses the psychopg3 adapter.

To install the client library, use pip:

python3 -m pip install "psycopg[binary]"
import psycopg as pg
import time

# Connect to an existing QuestDB instance

conn_str = 'user=admin password=quest host=127.0.0.1 port=8812 dbname=qdb'
with pg.connect(conn_str, autocommit=True) as connection:

# Open a cursor to perform database operations

with connection.cursor() as cur:

# Execute a command: this creates a new table

cur.execute('''
CREATE TABLE IF NOT EXISTS test_pg (
ts TIMESTAMP,
name STRING,
value INT
) timestamp(ts);
''')

print('Table created.')

# Insert data into the table.

for x in range(10):

# Converting datetime into millisecond for QuestDB

timestamp = time.time_ns() // 1000

cur.execute('''
INSERT INTO test_pg
VALUES (%s, %s, %s);
''',
(timestamp, 'python example', x))

print('Rows inserted.')

#Query the database and obtain data as Python objects.

cur.execute('SELECT * FROM test_pg;')
records = cur.fetchall()
for row in records:
print(row)

# the connection is now closed

For query examples, see Query & SQL Overview.

Query examples

For full query details and examples, see the PostgreSQL section in the Query & SQL Overview.

Compatibility

List of supported features

  • Querying (all types expect BLOB)
  • Prepared statements with bind parameters (check for specific libraries below)
  • INSERT statements with bind parameters
  • UPDATE statements with bind parameters
  • DDL execution
  • Batch inserts with JDBC
  • Plain authentication

List of supported connection properties

NameExampleDescription
databaseqdbShould be set to any value for example qdb, database name is ignored, QuestDB does not have database instance name
useradminUser name configured in pg.user or pg.readonly.user property in server.conf. Default value is admin
passwordquestPassword from pg.password or pg.readonly.password property in server.conf. Default value is quest
options-c statement_timeout=60000The only supported option is statement_timeout. It specifies maximum execution time in milliseconds for SELECT or UPDATE statement

List of unsupported features

  • SSL
  • Remote file upload (COPY from stdin)
  • DELETE statements
  • BLOB transfer

The following list of third party tools includes drivers, clients or utility CLIs that our team has tested extensively. Picking an item from it will guarantee that your code will work with QuestDB.

We recognize that our community might value some features more than others. This is why we encourage you to open an issue on GitHub if you think we are missing something important for your workflow.

CLIs

PSQL 12

Support for SELECT, INSERT, UPDATE, CREATE, DROP, TRUNCATE.

Libraries / Programmatic clients

node-postgres (NodeJS) 8.4

pq (Go) 1.8

pq (C) 12

Psycopg (Python) 2.9.3 and 3.1

ruby-pg (Ruby) 1.4.3

pg_connect (PHP) 8.1.0

Drivers

JDBC 42.2