Postgresql bulk insert

there are two minor problems:
1. The insertion time of postgresql is the same when executing batches. Is there any way to make them inconsistent?
2. When duplicate data already exists in the library, the entire execution fails. For example, 10 entries are inserted at a time, one of which is repeated in the library, and the whole 10 entries cannot be entered into the library. Is there any way to insert the other 9? Of course, it is a way to do a query between inserts to re-insert, but is there any way to let PG do it on its own?

Mar.04,2021

  1. use stored procedures to generate different times. For example,
CREATE OR REPLACE FUNCTION get_random_date(start_date date, end_date date) RETURNS integer AS  
$BODY$  
DECLARE  
    interval_days integer;  
    random_days integer;  
    random_date date;  
BEGIN  
    interval_days := end_date - start_date;  
    random_days := get_random_number(0, interval_days);  
    random_date := start_date + random_days;  
    RETURN date_part('year', random_date) * 10000 + date_part('month', random_date) * 100 + date_part('day', random_date);  
END;
  1. set a unique index for fields that you do not want to repeat. Then use insert into. On duplicate key update.
INSERT INTO table(column1, column2) VALUES(value1,value2) ON DUPLICATE KEY UPDATE column2 = VALUES(column2);

1) about time

PostgreSQL provides a series of functions to get the "current" time.
a) time when the current transaction starts: transaction_timestamp ()
b) time when the current statement starts: statement_timestamp ()
c) time when the current function is called: clock_timestamp ()

use clock_timestamp ().

https://www.postgresql.org/do.

2) about conflicts on insertion

The

Insert statement can specify an ON CONFLICT clause that defines how to resolve data conflicts when inserting:

a) DO NOTHING: does not insert conflicting data
modify the original record to a given value in case of b) DO UPDATE: conflict

https://www.postgresql.org/do.

Menu