bulk insert data with Postgres into QuestDB

Viewed 409

How does one bulk insert data with Postgres into QuestDB? The following does not work

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');
1 Answers

For inserting data in bulk, there are a few options. You can use CREATE AS SELECT to bulk insert from an existing table which is closest to your example:

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

Or you can use prepared statements, there are full working examples in a few languages in the QuestDB Postgres documentation, here is a snippet from the Python example:

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

Or you can bulk import from CSV, i.e.:

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