【问题标题】:bulk insert data with Postgres into QuestDB使用 Postgres 将数据批量插入 QuestDB
【发布时间】:2021-04-14 15:42:15
【问题描述】:

如何使用 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');

【问题讨论】:

    标签: questdb


    【解决方案1】:

    对于批量插入数据,有几个选项。您可以使用最接近您的示例的 CREATE AS SELECTbulk insert from an existing table

    CREATE TABLE employees
    AS (SELECT employee_id, last_name, first_name FROM existing_table)
    

    或者您可以使用准备好的语句,QuestDB Postgres documentation 中有几种语言的完整工作示例,这是 Python 示例中的 sn-p:

    # 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()
    

    或者你可以bulk import from CSV,即:

    curl -F data=@data.csv http://localhost:9000/imp
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-23
      • 2013-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-17
      相关资源
      最近更新 更多