如何使用 Postgres 将数据批量插入 QuestDB?以下不起作用
CREATE TABLE IF NOT EXISTS employees (employee_id INT, last_name STRING,first_name STRING);
INSERT INTO employees
(employee_id, last_name, first_name)
VALUES
(10, 'Anderson', 'Sarah'),(11, 'Johnson', 'Dale');
如何使用 Postgres 将数据批量插入 QuestDB?以下不起作用
CREATE TABLE IF NOT EXISTS employees (employee_id INT, last_name STRING,first_name STRING);
INSERT INTO employees
(employee_id, last_name, first_name)
VALUES
(10, 'Anderson', 'Sarah'),(11, 'Johnson', 'Dale');
对于批量插入数据,有几个选项。您可以使用从最接近您的示例的现有表中批量插入CREATE AS SELECT
:
CREATE TABLE employees
AS (SELECT employee_id, last_name, first_name FROM existing_table)
或者您可以使用准备好的语句, QuestDB Postgres 文档中有几种语言的完整工作示例,这是 Python 示例的片段:
# insert 10 records
for x in range(10):
cursor.execute("""
INSERT INTO example_table
VALUES (%s, %s, %s);
""", (dt.datetime.utcnow(), "python example", x))
# commit records
connection.commit()
或者您可以从 CSV 批量导入,即:
curl -F data=@data.csv http://localhost:9000/imp