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 1tJluS-0053e2-7q for pgsql-general@arkaria.postgresql.org; Sat, 07 Dec 2024 03:55:12 +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 1tJluP-00EtSo-6l for pgsql-general@arkaria.postgresql.org; Sat, 07 Dec 2024 03:55:10 +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 1tJluO-00EtSf-Ri for pgsql-general@lists.postgresql.org; Sat, 07 Dec 2024 03:55:10 +0000 Received: from mail-oa1-x2a.google.com ([2001:4860:4864:20::2a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tJluI-001SOb-Su for pgsql-general@lists.postgresql.org; Sat, 07 Dec 2024 03:55:09 +0000 Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-29666708da7so1569899fac.0 for ; Fri, 06 Dec 2024 19:55:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733543701; x=1734148501; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=08A9Tam9ayB/+0dFbK9eZ7fJqk6Ih7Oj5gvHWdrh0B8=; b=KAM4byXUcBr8F+F0neCmuRqeOYqaYhdRhMiF/b7TLu9DAWEPLKMc+hDfstPsF20Ui/ LyloS4/YB9Wu82M9bN/qdhaL9q8Iv8bPJcYXerSodLZ8VW2OVB9bkimnifIViE4I3jN7 HzOhhwmOkR5aaOmrS3Sd3xe3NBS6rjqbvQ9XOi7/ACxzDZglB9AV9g4WMQoHJDkWvwx9 o1CpDiADUg47SvU0QkhGP9xSjSvBEHyoKjY3V3mOqZbWVYBdmKHH4MK04I1MVlklt6wB D7i0APQR/8CiIjmo8A5BU58GZ6TOfKv0uUp/ES47eVC1eBU6AQ5VgFst9WVqn3YzV5Ml VX5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733543701; x=1734148501; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=08A9Tam9ayB/+0dFbK9eZ7fJqk6Ih7Oj5gvHWdrh0B8=; b=NDIAt2jUHrE2+rNUBmoHA0oop5VyfhMBVBrhARcoynjldQ+XmHJ+9AN5VyBjrSOQ7m A6rNMNEf5Ura0pJPp5QTN09f9RxDmgbRSvrpsFv6wfEkO93qdm3pdk8cTa6Lnpu4qXVw g1BVpq/8i3EF8TN9vYbHG0FdHm7HqH6SKIBhPwnYYKSOAIx6/roxUfqHNyt2IUIp4kqN LAgLamD9x80ilWAqJ9Dhm19U2SMdOqKptLwYa8ywZpnLnxaynvyaEGz8RVfRcF8hj8pw N9Y4tdkU0lXLNHlunCh/9WgRbAnS7ml97jlCKVJ5gsKehUPKdtt750H0qIN8oMCEBSqa E6RQ== X-Gm-Message-State: AOJu0Yzy4hGE3gO0ntRU6ADF4WohHYx2VJLuwxWIeuqapckTPR0hRcBK uwvGc+qnCgGvVjJVZN1HtzPx3oC8yhwgr54FDlrTozhgXy/hl/yGTNjFOt5XkSHt8gtYHalEL6+ A1BYQvMq99FAOiL182Z41A+wgA9xBz9Dd X-Gm-Gg: ASbGncs6mUcD/u+z4Dl3ov1dxl63NUCXA0KhwsF5lEul7rLDd3lilw8lUenqQtmVC0V PxKHP0JTDXJ4CiEmtfP81vRNSNxfChsg= X-Google-Smtp-Source: AGHT+IFWiXKpffSqQrw6UsHPmeeagdc7TDLTyxzFLZmZ+4+XapuqhwDEzON+hL/7qjorsC1W5c3DmEc/Ze0PDUNHZlY= X-Received: by 2002:a05:6870:fba3:b0:29e:76c8:be2e with SMTP id 586e51a60fabf-29f73860e11mr2716659fac.28.1733543700812; Fri, 06 Dec 2024 19:55:00 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a05:6802:3307:b0:577:9519:f64a with HTTP; Fri, 6 Dec 2024 19:55:00 -0800 (PST) In-Reply-To: References: From: "David G. Johnston" Date: Fri, 6 Dec 2024 20:55:00 -0700 Message-ID: Subject: Re: Insert records in the tavke only if they are not exist To: Igor Korot Cc: "pgsql-generallists.postgresql.org" Content-Type: multipart/alternative; boundary="0000000000007d5f1d0628a61848" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000007d5f1d0628a61848 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 and > 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 better avoided. Can=E2=80=99t you just run an installer/updater separate from run= ning the application? David J. --0000000000007d5f1d0628a61848 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Friday, December 6, 2024, Igor Korot <ikorot01@gmail.com> wrote:
When my application starts up, ot creates s= ome tables and insert records in them.

When the app starts for the second time it should check if t= he tables and the records in them are exist and skip the process.
Everything is good, except what i= f I have a connection from 2 different users?

I can run this inside transaction, but will this be e= nough? Will stating transaction lock the DB and the second user will wait f= or transaction to complete?


Seems like letting the create table fail would be = a reliable way to determine what is happening.=C2=A0 But this procedure ove= rall just seems better avoided.=C2=A0 Can=E2=80=99t you just run an install= er/updater separate from running the application?

= David J.

--0000000000007d5f1d0628a61848--