Multiple multithreaded insert - Mailing list pgsql-general

From Арсен Арутюнян
Subject Multiple multithreaded insert
Date
Msg-id 1476450753.144575536@f126.i.mail.ru
Whole thread Raw
Responses Re: Multiple multithreaded insert  (Scott Marlowe <scott.marlowe@gmail.com>)
Re: Multiple multithreaded insert  ("FarjadFarid\(ChkNet\)" <farjad.farid@checknetworks.com>)
List pgsql-general

Hi, everyone!

I have a table:

create table testpr(id serial,priority integer,unique(priority) DEFERRABLE, primary key(id));

and a trigger which, when added to this table, automatically sets priority as the maximum value +1

CREATE OR REPLACE FUNCTION PriorityCheck() RETURNS trigger AS $$

BEGIN

    NEW.priority := (SELECT coalesce(max(priority),0)+1 from testpr);

    RETURN NEW;

END;

$$ LANGUAGE plpgsql;

CREATE TRIGGER InsertTrigger BEFORE INSERT on testpr for EACH ROW

EXECUTE PROCEDURE PriorityCheck();

Will the priority be serial, when there is multithreaded addition of values to the table?

Which is:

Thread 1  insert into testpr(priority) values (1), (1), (1), (1), (1), (1), (1);

Thread 2  insert into testpr(priority) values (2), (2), (2), (2), (2), (2), (2);

The result (priority):

Thread 1: (1) (2) (3) (4) (5) (6) (7)

Thread 2: (8) (9) (10) (11) (12) (13) (14)

-- Arsen Arutyunyan

pgsql-general by date:

Previous
From: Albe Laurenz
Date:
Subject: Re: journaled FS and and WAL
Next
From: Scott Marlowe
Date:
Subject: Re: Multiple multithreaded insert