Long running INSERT+SELECT query

From: Vitaliy Garnashevich <vgarnashevich(at)gmail(dot)com>
To: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Long running INSERT+SELECT query
Date: 2018-04-26 16:13:17
Message-ID: 11ea9b74-243d-b275-be10-1004f51a4aa6@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

We're trying to populate a table with aggregated data from other tables.
For that we're running a huge INSERT+SELECT query which joins several
tables, aggregates values, and then inserts the results into another
table. The problem we're facing is that while the query is running ,
some records in tables referenced by the results table may be deleted,
which causes the following error:

ERROR:  insert or update on table "..." violates foreign key constraint
"..."
DETAIL:  Key (...)=(...) is not present in table "...".

Who do we make sure that such aggregating query would not fail?

Regards,
Vitaliy

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2018-04-26 17:19:24 Re: Long running INSERT+SELECT query
Previous Message Thomas Poty 2018-04-26 14:52:17 Re: Issue on public schéma with Pg_restore