Sunday, December 22, 2024

Postgres INSERT, 2x faster

using different SQL command can speed up insert 2x with Postgres DB

Boosting Postgres INSERT Performance by 50% With UNNEST

INSERT INTO sensors (ts, sensorid, value) 
  SELECT * 
  FROM unnest(
    $1::timestamptz[], 
    $2::text[], 
    $3::float8[]
)
      
instead
INSERT INTO sensors (sensorid, ts, value)
VALUES 
  ($1, $2, $3), 
  ($4, $5, $6), 
   ..., 
  ($2998, $2999, $3000);

No comments: