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 1tJzbW-006DiX-1y for pgsql-general@arkaria.postgresql.org; Sat, 07 Dec 2024 18:32:34 +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 1tJzbT-00GTyK-Hi for pgsql-general@arkaria.postgresql.org; Sat, 07 Dec 2024 18:32:32 +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 1tJzbS-00GTyC-0t for pgsql-general@lists.postgresql.org; Sat, 07 Dec 2024 18:32:32 +0000 Received: from fout-a5-smtp.messagingengine.com ([103.168.172.148]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tJzbO-001Y8R-T1 for pgsql-general@lists.postgresql.org; Sat, 07 Dec 2024 18:32:30 +0000 Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id 0FAEC1383702; Sat, 7 Dec 2024 13:32:25 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Sat, 07 Dec 2024 13:32:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1733596345; x=1733682745; bh=DtLN83RlcxyczPxZ5ScfTsrIKXocoiOWebXMaR4Z7kk=; b= V94xCr4fjJ6PlFTz2LqdEkCvV0je2CrSbgnHF8DvujiYm4usPtmFBBUZFl6hXUdd p+mz85W+aEQH3vFiDDf+ySlwn2gWBZWwgLuW+AI1TEpbbYdtmKf+USlG0rYeCny9 nFzpOcbWhQAkbI/HyLlEe4cC9ynOanBvAyFk+Z4Wv2QJPMLShDWKgcPabO5IX+iC 7t1y4xlv6QuT4IxHjFWYhI9jITDtMcQcLcU9nkIcieQicl3FFia2gnZHFoitYvN6 TFduqWWREgTF0TPV03tWGmHhymf1Ad5ohuyupMaG9bNweHr+h42J6tV3ro+desvl fZ9xj5QWaoryln0KGRWnpA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1733596345; x=1733682745; bh=D tLN83RlcxyczPxZ5ScfTsrIKXocoiOWebXMaR4Z7kk=; b=rJ6LJAMsEJT+9dX9E a1Cw9GAK+1vFZf8OoOw/fjqmtlG0bJGLAwH3Ool+1yUn/uAUJDSG+iWis5ZicKhD PFoMEqZr4r2BiuJSMXM/gay6zAD6VE59EbnqbyJAEiat/8dFnVV+sWWs28wkOCNX /mg2qKMjNNXUoVBonaszei9grhJQextBzs3bowH2PhH6q40s/hPSVhNYLFM34dk5 EfgkOAwfceecYS3FjgRFbx0VROV0vvgTF5LtZeIfkk+ibZpQXgbEjTqa5ZTkLkxJ 3L7TVtBuokfWaIA0673M8bLu1IeEEcbRqc8r97jTerxP+YxiB56VpxdqoLhfxa9f m8RiQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrjedugdduuddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepkfffgggfuffvfhfhjggtgfesthekredttddvjeen ucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrse grkhhlrghvvghrrdgtohhmqeenucggtffrrghtthgvrhhnpeffleegieefgfevudehtdfh keeutdffjeevgeffgeejvedthefgudeiteefheejheenucevlhhushhtvghrufhiiigvpe dtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhl rghvvghrrdgtohhmpdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprh gtphhtthhopehikhhorhhothdtudesghhmrghilhdrtghomhdprhgtphhtthhopehpghhs qhhlqdhgvghnvghrrghlsehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 7 Dec 2024 13:32:24 -0500 (EST) Message-ID: Date: Sat, 7 Dec 2024 10:32:23 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Insert records in the tavke only if they are not exist To: Igor Korot , "pgsql-generallists.postgresql.org" References: <8770b693-0c44-40de-b883-36cc5e718a0a@aklaver.com> Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12/7/24 09:59, Igor Korot wrote: > Hi, Adrian, > > On Sat, Dec 7, 2024 at 11:18 AM Adrian Klaver wrote: >> >> On 12/6/24 19:36, Igor Korot wrote: >>> Hi, All, >>> >>> 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. >> >> Does this also apply to starts after the second time? > > Yes, it does. > > However, if the new table is created in the meantime - the new record > should be created, because it is not there yet. What determines that a new table needs to be created and populated? > >> >> Is the data expected to change over time? > > Data change is possible. > > This is one of the tables: > > "CREATE TABLE IF NOT EXISTS \"sys.abcatfmt\"(\"abf_name\" char(30) > NOT NULL, \"abf_frmt\" char(254), \"abf_type\" smallint, \"abf_cntr\" > integer" ));"; > "CREATE UNIQUE INDEX IF NOT EXISTS pbcatf_x ON > \"sys.abcatfmt\"(\"abf_name\" ASC);"; > > My understanding is that "INSERT OR IGNORE" will check the unique It is INSERT ... ON CONFLICT DO NOTHING | UPDATE. > index and will not do anything if the recrd > with such data on the index already exists. So you have the option of either skipping the insert or updating selected fields in the row. > >> >>> >>> Everything is good, except what if I have a connection from 2 different >>> users? >> Is it possible to have the app start up without external users connecting? > > Not sure what you mean here. > > Are you asking if the computer can run the app? > Then the answer is NO. App is always started by the user. > Please clarify. This is going to need a more detailed explanation of what 'app' means. Are you talking about the front end that the user launches or the backend that runs the database or something else? > > Thank you. > >> >>> >>> 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? >>> >>> Thank you. >>> >> >> -- >> Adrian Klaver >> adrian.klaver@aklaver.com >> -- Adrian Klaver adrian.klaver@aklaver.com