对付查询和数据输出,QuestDB与PostgreSQL查询兼容。
这意味着您可以在QuestDB中利用您最喜好的PostgreSQL客户端或驱动程序。
有关信息查询和数据输出,请参阅查询和SQL概述

注:PostgreSQL的存储模型与QuestDB的存储模型有着根本的不同。因此,Postgres的一些功能在QuestDB中不存在。
1.插入示例1.1psql创建表:
psql -h localhost -p 8812 -U admin -d qdb \ -c "CREATE TABLE IF NOT EXISTS t1 (name STRING, value INT);"
插入数据:
psql -h localhost -p 8812 -U admin -d qdb -c "INSERT INTO t1 VALUES('a', 42)"
查询数据:
psql -h localhost -p 8812 -U admin -d qdb -c "SELECT FROM t1"
请把稳,您也可以从Docker运行psql,而无需在本地安装客户端:
docker run -it --rm --network=host -e PGPASSWORD=quest \ postgres psql ....
1.2Python
此示例利用psychopg3适配器。
要安装客户端库,请利用pip:
python3 -m pip install "psycopg[binary]"
import psycopg as pgimport time# Connect to an existing QuestDB instanceconn_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
2.查询示例
通过默认端口8812利用PostgreSQL端点查询QuestDB。下面显示了Python措辞的示例。
import psycopg as pgimport time# Connect to an existing QuestDB instanceconn_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: #Query the database and obtain data as Python objects. cur.execute('SELECT FROM trades_pg;') records = cur.fetchall() for row in records: print(row)# the connection is now closed
3.兼容性
支持的功能列表:
查询(除BLOB外的所有类型)已准备好带有绑定参数的语句(请查看下面的特定库)带绑定参数的INSERT语句带绑定参数的UPDATE语句DDL实行利用JDBC批量插入普通身份验证支持的连接属性列表:
Name
Example
Description
database
qdb
应设置为任何值,例如“qdb”,忽略数据库名称,QuestDB没有数据库实例名称
user
admin
在server.conf中的pg.User或pg.readonly.User属性中配置的用户名。默认值为admin
password
quest
密码来自server.conf中的pg.Password或pg.readonly.Password'属性。默认值为quest`
options
-c statement_timeout=60000
唯一支持的选项是statement_timeout。它指定SELECT或UPDATE语句的最大实行韶光(毫秒)
不支持的功能列表:
SSL远程文件上传(从“stdin”进行“COPY”)DELETE 语句BLOB 传输4.推举的第三方工具以下第三方工具列表包括我们团队广泛测试的驱动程序、客户端或实用程序CLI。从中选择一个项目将担保您的代码可以与QuestDB一起事情。
我们认识到,我们的社区可能更重视某些功能。这便是为什么如果你认为我们短缺对你的事情流程主要的东西,我们鼓励你在GitHub上打开一个问题。
CLIsPSQL 12支持 SELECT, INSERT, UPDATE, CREATE, DROP, TRUNCATE.
5.库/程序化客户端node-postgres (NodeJS) 8.4pq (Go) 1.8pq (C) 12Psycopg (Python) 2.9.3 and 3.1ruby-pg (Ruby) 1.4.3pg_connect (PHP) 8.1.06.驱动JDBC 42.2