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 1tJm1e-0054NR-QI for pgsql-general@arkaria.postgresql.org; Sat, 07 Dec 2024 04:02:38 +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 1tJm1c-00Ewsx-98 for pgsql-general@arkaria.postgresql.org; Sat, 07 Dec 2024 04:02:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tJm1b-00Ewsp-UT for pgsql-general@lists.postgresql.org; Sat, 07 Dec 2024 04:02:37 +0000 Received: from mail-yb1-xb30.google.com ([2607:f8b0:4864:20::b30]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tJm1a-001Rxk-ES for pgsql-general@lists.postgresql.org; Sat, 07 Dec 2024 04:02:35 +0000 Received: by mail-yb1-xb30.google.com with SMTP id 3f1490d57ef6-e3988fdb580so2369577276.2 for ; Fri, 06 Dec 2024 20:02:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733544154; x=1734148954; 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=HRLhMIAIk16FbKk9vxVn+WO6ZaUAUtudRNwgGpuRodU=; b=R2vI1lmqwPOMITM1LvMIR4F8ZdE9p+PSWCcDTWkLNoLqwKO7VSC02H8SzLDCSD4RVU HY04AOhZWT3Wu+mlZB/wYIA9VFw2Ew1LRWywiPFGeFEoUwUTyg8b3UF9OnVm7voEG4sf eG7ut6U1EHlzbjNsVkw6921OmmENQ0RHEWTVMoosFmqlm5PguZldo0+U8okdslg0gLWI nejjkwAhFkt7A9Eg1QBBzhW920Cy+sCbBZ03LbFbfu015zVPynUj9xzKltmtcO8YKuGs Av0bsd7dgP3zv73KF/vwOvzHg4xaiU2HYKB13tGbYgGi+qUdjJY/vYhtt5caHFKf0YlH b4+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733544154; x=1734148954; 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=HRLhMIAIk16FbKk9vxVn+WO6ZaUAUtudRNwgGpuRodU=; b=w48HxpoVTb7umij5YKlZav2IQ9QPV3XwsX1sifD6+HyyHXI5G404YcEQj9tRk4VTeY ppcBUHX+wej4b9/cv2JMWdlMtJC0Tw3z0AvJbBmB5TWY5lqC6s9YMHNMIGw1OufQwpqi BYhrbNUBbQcv9UUv5ye1XPPXu77N1Bdf50oRk3SWPcApsYwLDwGL9k10rzDpJR4mwfTP DoFvBeE8JlkSsUeujYU3jNou3i7X2I8ReO3u5jXUangO3+GxgrIbwh5OEqhbB9acGOXA JYhPfr+MbtuYHw6IHT/JHaSeXtDFdT6/hmON+Gi6P/MyEooGCnS+86sY5u2KO4M3cXwa NVHA== X-Gm-Message-State: AOJu0Yyz0SbHhIlPVirNfxMjMOhtp8dRy8gdg6xtv3oqoHPr3V48/sUY fs5reUDneAhgbPiK159+pcy/rKT5OHxtpMo5NaCsl9gZjkL9XulSQWsTBlmYTv/Q9sxV5hTdnwO Lbcw9ddXBF1Y0XAi+W1DmYjScmWM= X-Gm-Gg: ASbGncsdrXIg6uJmdIO9Zh9bK9/ytYdwDXVBNnPOzOZBwFj+F4N0h+i1PmdaOuIR7/C cFh26t31MCDDmdx+MbcfFLakR9Fnq7m9ec5Yn68Q3Htzcc8GY4yT5/2leHulKv42S X-Google-Smtp-Source: AGHT+IHT4xgIIULrRLFW/24Bib/YpFqzSygiXRErjhddfCWM5lQ4Ft+W7jhVoDWN6yzn0WN55rnFBtHmeMp+GJ0ZWoY= X-Received: by 2002:a05:6902:200f:b0:e39:9937:db2b with SMTP id 3f1490d57ef6-e3a0b131f57mr4744832276.25.1733544153722; Fri, 06 Dec 2024 20:02:33 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Igor Korot Date: Fri, 6 Dec 2024 22:02:22 -0600 Message-ID: Subject: Re: Insert records in the tavke only if they are not exist To: "David G. Johnston" Cc: "pgsql-generallists.postgresql.org" Content-Type: multipart/alternative; boundary="0000000000007c375c0628a6334c" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000007c375c0628a6334c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, Dvid, On Fri, Dec 6, 2024, 9:55=E2=80=AFPM David G. Johnston wrote: > On Friday, December 6, 2024, Igor Korot wrote: >> >> When my application starts up, ot creates some tables and insert records >> in them. >> >> When the app starts for the second time it should check if the tables an= d >> the records in them are exist and skip the process. >> >> Everything is good, except what if I have a connection from 2 different >> users? >> >> I can run this inside transaction, but will this be enough? Will stating >> transaction lock the DB and the second user will wait for transaction to >> complete? >> >> > Seems like letting the create table fail would be a reliable way to > determine what is happening. But this procedure overall just seems bette= r > avoided. Can=E2=80=99t you just run an installer/updater separate from r= unning the > application? > Interesting idea bout the installer. Except those tables will contain some additional info about the schema and the application. So if I create/remove new table, either in my app or from psql the record will need to be inserted/deleted. Thank you. > David J. > > --0000000000007c375c0628a6334c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi, Dvid,

On Fri, Dec 6, 2024, 9:55=E2=80=AFPM David G.= Johnston <david.g.johnsto= n@gmail.com> wrote:
On Frida= y, December 6, 2024, Igor Korot <ikorot01@gmail.com> wrote:
When my applic= ation starts up, ot creates some tables and insert records in them.

When the app starts for the sec= ond time it should check if the tables and the records in them are exist an= d skip the process.

Ever= ything is good, except what if I have a connection from 2 different users?<= /div>

I can run this inside tr= ansaction, but will this be enough? Will stating transaction lock the DB an= d the second user will wait for transaction to complete?


Seems like letting th= e create table fail would be a reliable way to determine what is happening.= =C2=A0 But this procedure overall just seems better avoided.=C2=A0 Can=E2= =80=99t you just run an installer/updater separate from running the applica= tion?

Interesting idea bout the installer.
Except t= hose tables will contain some additional info about the schema and the appl= ication.

So if I create/= remove new table, either in my app or from psql the record will need to be = inserted/deleted.

Thank = you.


David J.

--0000000000007c375c0628a6334c--