Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rj0E5-002uEh-W1 for pgsql-sql@arkaria.postgresql.org; Sat, 09 Mar 2024 17:11:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rj0E4-001ZO1-El for pgsql-sql@arkaria.postgresql.org; Sat, 09 Mar 2024 17:11:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rj0E4-001ZNr-4W for pgsql-sql@lists.postgresql.org; Sat, 09 Mar 2024 17:11:12 +0000 Received: from mail-oa1-x35.google.com ([2001:4860:4864:20::35]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rj0E1-003dmc-2t for pgsql-sql@lists.postgresql.org; Sat, 09 Mar 2024 17:11:11 +0000 Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-21e8a740439so1586910fac.1 for ; Sat, 09 Mar 2024 09:11:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710004267; x=1710609067; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=bTKZj9VFJX8tMkoaykjt1JOS4Mv3Yy8Qf3YeG7Primo=; b=bydpE/WzcLyyFPoe7bbG3Spcm2seomKWptpOr6c3VYVIAOoBpk6psyFn5sSRw8EIQ/ /jB7Tf3SgB4XgfN7sBAM9I01ctCu0PMljcW3+rbw24Bl/3qT43HdmXTJFGHycKxTioo5 Uc0cGdplq8lmR8jKoQns2rkWmv7P/+yi1ESRJjdHQ4xTogULG+mb321wIWMOrU/Eqx3s YgQLP6tYuOz1D+7Xdjctp/Qau7jmGSwJoYNv7UxunZ5rIjDjeZL8UN5Xo2FeDNhtuQwI NAGTFoNkhCJK5DHtH7Y1kjaIBj454zwcoE/S3nuNBB1ENeZdjHErfukVLpD4SpMge0o8 EPSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710004267; x=1710609067; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bTKZj9VFJX8tMkoaykjt1JOS4Mv3Yy8Qf3YeG7Primo=; b=G7VtGMzECqgIgLCbajOnhpZLT+xhnnhDWYJq6E+FNrKSAO7cVrQYorJxu+yVeVQDrz ZkH6iCRUZp9xVDNmN4Hp57En/aUsgQ4U8sWyJsx7rMw3q8QCu7mcLN8JSh90NXPLnhQ5 N8sdIWyjicHjcg+xgTjU+nVqKRUMhqzAjj0MwoOFgrpSIeBt09xqFHVPHpeWbMjv+zyF pIyGblqqS2518TbnH5bx3noPJYLVTIfr3QiLvqO/M+ur56KfXV9yLoXUr//s8hbld/Jz dvan/vn6MttTdXCGgzIzeCo2n7Wxqh4smeeYYiWKtV1F7AZeXB/Wff9hEbf881EO/D18 4i1w== X-Gm-Message-State: AOJu0Yz1GYX4vbfVlJqW5XIhdusQ93hn44PIuoMO/h9V+X6sOwqDqR2N zXq8TZYyFFme4VnJ7Q9P5i3+uIfMmHXkURW6rDSpVAwgG7KrzyweKBD1/NwQLftWp87/vkQm1tn PVE/wDAbnlEiC5EXqDh3ztt2OFqpdFcksq3s= X-Google-Smtp-Source: AGHT+IEqvx/bu48j30mht3ytiDVVlThfMcI2yH2hVhnfTKDa18KDsXmtHlLhRxaoZeJ2L8ECkIDhSmw4nwn9P7Np2uc= X-Received: by 2002:a05:6870:d699:b0:221:7a13:3aa2 with SMTP id z25-20020a056870d69900b002217a133aa2mr1362100oap.6.1710004267325; Sat, 09 Mar 2024 09:11:07 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: intmail01 Date: Sat, 9 Mar 2024 20:11:28 +0300 Message-ID: Subject: Re: How to know if all insertions are finished To: Steve Midgley Cc: pgsql-sql@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000eb243106133d6438" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000eb243106133d6438 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable >I think you are saying in your last line that each insert line is treated as an individual statement, so you get a bunch of trigger notifications instead of just one, and >you don't know how to detect when you have received the final insert? Yes. That is the problem. I do not code to insert data, it is done by drag/move from calc sheet to table graphically. The dummy row may be the solution with the risk you mention. Thanks. On Fri, Mar 8, 2024 at 7:27=E2=80=AFPM Steve Midgley w= rote: > > > On Fri, Mar 8, 2024 at 4:01=E2=80=AFAM intmail01 wr= ote: > >> Hi, >> >> Is there any way to know if several insertion are terminated. >> I use libreoffice base to import at the same time many lines. When all >> lines are inserted I have to do some data check. I dont find any way to >> know if the insertion ends to start some function automatically. >> I tried to use a STATEMENT trigger type but all lines are treated as >> statement. >> > > I think you are saying in your last line that each insert line is treated > as an individual statement, so you get a bunch of trigger notifications > instead of just one, and you don't know how to detect when you have > received the final insert? > > The first thing I'd look for is whether I could wrap all the libreoffice > inserts into a single transaction block, and then event off of the > transaction block completing. > > Barring that, and noting I'm not familiar with how libreoffice would send > the inserts, one option could be to put a listen/notify pattern at the en= d > of your insert code, if it's possible to add a line of sql at the end of > the inserts? Of course, if you can do that, you might also be able to wra= p > the whole thing with a transaction, but listen/notify might be simpler to > event off of.. > > -- In session/connection 1 > BEGIN; > -- Perform your bulk insert operation here > COMMIT; > NOTIFY inserts_done; > > -- In session/connection 2 > LISTEN inserts_done; > -- Once notification is received, proceed with necessary operations > > If you can't do something like this, the only other (relatively horrible) > things I can think of would be to: > > 1. Put a dummy row at the end of your insert data (if you can > guarantee it would be inserted last during the bulk operation), and th= en > build a trigger/condition to detect insertion of a row matching the du= mmy > data that deletes the dummy row and then proceeds to kick off whatever > other processes you want, or: > 2. Use a time based model, where you build an understanding of how > long your inserts take to execute, and build a monitor that kicks off = on > each insert, and if another insert is not detected within a certain am= ount > of wait time, you conclude that there are no more inserts coming, and = you > then kick off whatever other processes you want.. > > Hopefully someone with deeper Postgres knowledge has other, more reliable > solutions that leverage Postgres, but if your inserts are all discrete, a= nd > you don't have control over the sql itself. > > Steve > --000000000000eb243106133d6438 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
>I think you are saying in your last line that eac= h insert line is=20 treated as an individual statement, so you get a bunch of trigger=20 notifications instead of just one, and >you don't know how to detect= when you have received the final insert?
Yes. That is the = problem.

I do not code to insert data, it is done = by drag/move from calc sheet to table graphically.

The dummy row may be the solution with the risk you mention.
Thanks.

On Fri, Mar 8, 2024 at 7:27=E2=80=AFPM Steve = Midgley <science@misuse.org>= ; wrote:


On Fri, Mar 8, 2024 at 4:01= =E2=80=AFAM intmail01 <intmail01@gmail.com> wrote:
Hi,

Is there any way to know if several insertion are terminated.
I= use libreoffice base to import at the same time many lines. When all lines= are inserted I have to do some data check. I dont find any way to know if = the insertion ends to start some function automatically.
I tried = to use a STATEMENT trigger type but all lines are treated as statement.
=

I think you are sa= ying in your last line that each insert line is treated as an individual st= atement, so you get a bunch of trigger notifications instead of just one, a= nd you don't know how to detect when you have received the final insert= ?

The first thing I'd look for is whether I co= uld wrap all the libreoffice inserts into a single transaction block, and t= hen event off of the transaction block completing.

Barring that, and noting I'm not familiar with how libreoffice would s= end the inserts, one option could be to put a listen/notify pattern at the = end of your insert code, if it's possible to add a line of sql at the e= nd of the inserts? Of course, if you can do that, you might also be able to= wrap the whole thing with a transaction, but listen/notify might be simple= r to event off of..

= -- In session/connection 1
BEGIN;=
-- Perform your bulk insert oper= ation here
COMMIT;
NOTIFY inserts_done;

-- In sessio= n/connection 2
LISTEN inserts_don= e;
-- Once notification is receiv= ed, proceed with necessary operations

If you can't do something like this, the only other (relatively horrib= le) things I can think of would be to:
  1. Put a dummy row at= the end of your insert data (if you can guarantee it would be inserted las= t during the bulk operation), and then build a trigger/condition to detect = insertion of a row matching the dummy data that deletes the dummy row and t= hen proceeds to kick off whatever other processes you want, or:
  2. Use= a time based model, where you build an understanding of how long your inse= rts take to execute, and build a monitor that kicks off on each insert, and= if another insert is not detected within a certain amount of wait time, yo= u conclude that there are no more inserts coming, and you then kick off wha= tever other processes you want..
Hopefully someone with deepe= r Postgres knowledge has other, more reliable solutions that leverage Postg= res, but if your inserts are all discrete, and you don't have control o= ver the sql itself.

Steve
<= /div> --000000000000eb243106133d6438--