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 1tK3vt-006czG-6O for pgsql-general@arkaria.postgresql.org; Sat, 07 Dec 2024 23:09:53 +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 1tK3vq-00HWfj-LB for pgsql-general@arkaria.postgresql.org; Sat, 07 Dec 2024 23:09:51 +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 1tK3tX-00HSYw-4f for pgsql-general@lists.postgresql.org; Sat, 07 Dec 2024 23:07:28 +0000 Received: from fhigh-a3-smtp.messagingengine.com ([103.168.172.154]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tK3tV-001ZUy-7k for pgsql-general@lists.postgresql.org; Sat, 07 Dec 2024 23:07:26 +0000 Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfhigh.phl.internal (Postfix) with ESMTP id A1C14114013B; Sat, 7 Dec 2024 18:07:23 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Sat, 07 Dec 2024 18:07:23 -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=1733612843; x=1733699243; bh=e6B9RJMTPEZXX57uQd/6U8tyxZgJrFwBZC6rHx57vIA=; b= kUhtpAMdvaxSbCvPxoLdn/6ilLuxJshCC1HRW9CbKoOE49nFJmt70OX7vVHtoFgP U164lU8Etg1vT9oDPVCo2Ci+p/9+QqhOIYKVJ7qO1bhaCin4z4EZ+qogo5g8NuBs HoHT7CyMtT11smASg1X1BUTwzcQ5/h2snEQuXRHBIGtThIMotDIhlnp2HTFs4zsU jS1Ouq/pFb5kCu9tkBdcvm4DI891xfegwvcXx1paThE1DpAlkRzvFckKcFdBOUu9 TmCUMQzqBsqJY+IWbc3CH36d/1J7kRI9JCQeUAXtnhlzR1ENnBSIcAMjM93U0gvA O8fBVApSMhWe5KXAshrzjA== 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=1733612843; x=1733699243; bh=e 6B9RJMTPEZXX57uQd/6U8tyxZgJrFwBZC6rHx57vIA=; b=agRf+HGhvdreBlmOg A+JdeOIxahV9Ii7/9aDkqTovs1CSfkOJTJqqllFliiYsB9vwVGKaYR/0z0ppxg2N akm28BIktx8XHUtNP5JPpgElFPsAlG1eo4/QNfFPQyqhWYKBvLxtMqZQnpAhKJN/ TKbGm+CTGAB8uJPFw7aeECRm1SQWUdxiiNIlNdutUyHHLohAS8otrN7YAcT3XeWm Z0OWvB2nL4V2DRust+njq1jH7LsmjvRCoplLGJ1EH9J1dp0tn9sxKyVFt5A1QDqZ IsZRNMOVmQBTUgZb7ZwxVoabOsm31HMWg7tGz12F5IpUf7kr7V1aSs/sDOsfQDFx lcRjA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrjedvgddthecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtkeertddtvdejnecu hfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrg hklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepffelgeeifefgveduhedthfek uedtffejveegffegjeevtdehgfduieetfeehjeehnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgr vhgvrhdrtghomhdpnhgspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtg hpthhtohepihhkohhrohhttddusehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhq lhdqghgvnhgvrhgrlheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 7 Dec 2024 18:07:22 -0500 (EST) Message-ID: Date: Sat, 7 Dec 2024 15:07:22 -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 12:17, Igor Korot wrote: > Hi, Adrian, > > On Sat, Dec 7, 2024 at 12:32 PM Adrian Klaver wrote: >> >> 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? > > Consider the following scenario: I did and it made me start twitching. > > 1. Program is installed. > 2. Program is started for the first time. > 3. My tables are created and populated What distinguishes your tables from other users tables? > 4. Program is executed. > 5. User closes the program. > 6.. Later on the user decides that there is a need > for another table (inside psql or any other client) The above is where I started twitching. How do you keep them out of your tables? How do you get these changes to play nice with the existing structure? > 7. Then the program starts for the second time. > > At this time all my tables that were created will stay (courtesy > of CREATE TABLE IF NOT EXIST). You are depending on folks not knowing about DROP TABLE and/or you having thought out the permissions for access thoroughly. > All records that were there are staying unchanged. INSERT/UPDATE against your tables is not a possibility? > However, for the table that was made in between the runs > will be added > > Now if the program is installed on 2 different machines > and started simultaneously on both - I want to ensure that > only 1 set of tables is made and only 1 set of records in them > is available I assume this means they are both pointing at the same instance of a database? This is the part that confuses me. If you are going to allow ad hoc and at will changes how do you know what is actually the correct change? > > Now, the creation/population is done inside a transaction. I'm not sure that a transaction is going to solve the issue I raised above, it will just make one thing happen with no guarantee that it is the correct outcome. >> Are you talking about the front end that the user launches or the >> backend that runs the database or something else? > > Front-end. > This is a C++ app. To me this is the tail wagging the dog. The thought of allowing users to change the database structure and you dealing with it after the fact is just disturbing to me. > >> >> >>> >>> Thank you. -- Adrian Klaver adrian.klaver@aklaver.com