我正在使用 Python 进行一些测试,我希望能够通过 REST 运行 SQL 查询。有没有一种简单的方法可以使用请求来运行查询,例如:
requests.get('http:myserver:9000/exec' query="select * from my_table")
我正在使用 Python 进行一些测试,我希望能够通过 REST 运行 SQL 查询。有没有一种简单的方法可以使用请求来运行查询,例如:
requests.get('http:myserver:9000/exec' query="select * from my_table")
如果您需要通过 Python 使用 REST,这可以类似于以下示例完成:
import requests
import json
host = 'http://myserver:9000'
sql_query = "select * from my_table limit 100"
query_params = {'query': sql_query}
try:
response = requests.post(host + '/exec', params=query_params)
json_response = json.loads(response.text)
rows = json_response['dataset']
for row in rows:
print(row)
except requests.exceptions.RequestException as e:
print("Error: %s" % (e))
QuestDB REST 文档页面上对此有其他文档