ERROR : 'tuple concurrently updated' - Mailing list pgsql-hackers

From Stéphan BEUZE
Subject ERROR : 'tuple concurrently updated'
Date
Msg-id 525E85AD.3030705@douane.finances.gouv.fr
Whole thread Raw
Responses Re: ERROR : 'tuple concurrently updated'  (Robert Haas <robertmhaas@gmail.com>)
Re: ERROR : 'tuple concurrently updated'  (Amit Kapila <amit.kapila16@gmail.com>)
Re: ERROR : 'tuple concurrently updated'  (Stéphan BEUZE <stephan.beuze@douane.finances.gouv.fr>)
List pgsql-hackers
The following query is performed concurrently by two threads logged in 
with two different users:
    WITH raw_stat AS (        SELECT           host(client_addr) as client_addr,           pid ,           usename
 FROM           pg_stat_activity        WHERE           usename = current_user    )    INSERT INTO my_stat(id,
client_addr,pid, usename)        SELECT             nextval('mystat_sequence'), t.client_addr, t.pid, t.usename
FROM(            SELECT                client_addr, pid, usename            FROM                raw_stat s
WHERE               NOT EXISTS (                   SELECT                      NULL                   FROM
       my_stat u                   WHERE                      current_date = u.creation                   AND
          s.pid = u.pid                   AND                      s.client_addr = u.client_addr                   AND
                   s.usename = u.usename                )        ) t;
 
From time to time, I get the following error: "tuple concurrently updated"

I can't figure out what throw  this error and why this error is thrown. 
Can you shed a light ?

-------------------------------
Here is the sql definition of the table mystat.

**mystats.sql**
    CREATE TABLE mystat    (      id bigint NOT NULL,      creation date NOT NULL DEFAULT current_date,
      client_addr text NOT NULL,      pid integer NOT NULL,      usename name NOT NULL,      CONSTRAINT
statistiques_connexions_pkeyPRIMARY KEY (id)    )    WITH (      OIDS=FALSE    );
 



pgsql-hackers by date:

Previous
From: "MauMau"
Date:
Subject: Re: Auto-tuning work_mem and maintenance_work_mem
Next
From: Robert Haas
Date:
Subject: Re: Triggers on foreign tables