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 1tK4hY-006hee-Aj for pgsql-general@arkaria.postgresql.org; Sat, 07 Dec 2024 23:59:08 +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 1tK4hV-0002wO-NH for pgsql-general@arkaria.postgresql.org; Sat, 07 Dec 2024 23:59:06 +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 1tK4hV-0002wG-82 for pgsql-general@lists.postgresql.org; Sat, 07 Dec 2024 23:59:06 +0000 Received: from mail-yb1-xb29.google.com ([2607:f8b0:4864:20::b29]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tK4hT-001Zou-QC for pgsql-general@lists.postgresql.org; Sat, 07 Dec 2024 23:59:05 +0000 Received: by mail-yb1-xb29.google.com with SMTP id 3f1490d57ef6-e39841c8fd6so3341798276.3 for ; Sat, 07 Dec 2024 15:59:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733615943; x=1734220743; darn=lists.postgresql.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=VBI1GD6vXAFqigIYlT20STWnbp0+BpNauOZ89gG+8EI=; b=Vx6ZHTHcrqX2ku28HnlcLFRSkPSso2u3vm+XDeUJClI9EVi7w1wyqm0VGjztMYpVwP s3SkAleqmTpUAiJTHjrLFEhg0brPs+AJVzgQ1rooJhWHq25IEBDAffhjTrwSne/1ck9W lCgTise7ovHXkd0Op1uW+MGLSADXpyJ6o/QiIC/PXecuh0eifdTIdb1hi87fAWo9qnAj dycRX7MJTfc6SIe9h2pe7f1VEM3nVYqimvKGrqGUI5qBEQr8YvgRIiAbL8nL5EAbqwVQ dNKhs1ql8sHSExgxX4xLieJPZ4M1DRoSeBVthlIvf0wyPspCB/23kLjxdPOfqx7WTzz9 GvGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733615943; x=1734220743; h=content-transfer-encoding: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=VBI1GD6vXAFqigIYlT20STWnbp0+BpNauOZ89gG+8EI=; b=ARFUsrhpiKYiIChrGkKJmJyyf+ptOFNteXnEdj6atXu+rDEiecQQsPnev+asFgA8Az N8yoSTXG9n6tyEx3WXh896QlZ3wTsOOAkj4ZTqAtFCC1W3JK00UWlTjGWD0TYFKCOBGj Wt/QwV3s/0Hxa/dwn+Q/UNpxgU5zhj6771GACni4Br52g9ayMScIc8BKLxUw8BblI+aF j/6Hum4gHiUcgcVVDKx/2z1wePQqYa5nvAdRnVbviHR5y6Y5Jrvah+MLI7NfQ1TdlpRo +oLlDXI9zSgdRDsKaX5C+9LgeBDPRoCnMTq7s4XDd2SDjzaChpLXBLlhFvBXlOfierJn 4deg== X-Forwarded-Encrypted: i=1; AJvYcCWvctWv7UVevsi3jxFncJ/C+ro2g0ZqIAIf5BD3fbUwPtHQeho5KpKslAmJGgTfNt6QJX5meXMkwVgFIS2P@lists.postgresql.org X-Gm-Message-State: AOJu0YwFrJsbm+Lu9b++GVnW6f5h5Kwd51txtulaH7+ypFvdlcQfXmj3 Ovy6wxL1dWXTueEMLo5uEztBgvggvWnQtMTewj8OyZ7h1On4frZXmQa4pjN8CbZfIgUS01e+nLn 6V1WDyAIodMOEWL8FLopxEx+u4If+lA== X-Gm-Gg: ASbGncthkmuv/xiW+OzmI1sejBzR6fiDC7SdO+OlXdfdcGqHmmbzNHf18oO3ov29s/O bOArACR7263NgpbUBvFB/FjtIccDmn9llsXtB8iro0eJ+LRXfjl84s2cVLY+Wli5F X-Google-Smtp-Source: AGHT+IGsGkxLNBFMUFR79XYuhxCGbnEaNJpMacue8Vbnu3LK/jrF5va4LdE/6nFlQeYIYjXLslbCjJooiDK08LG+wa8= X-Received: by 2002:a05:6902:248a:b0:e39:8174:7f2c with SMTP id 3f1490d57ef6-e3a0b4d09d5mr6804854276.46.1733615942681; Sat, 07 Dec 2024 15:59:02 -0800 (PST) MIME-Version: 1.0 References: <8770b693-0c44-40de-b883-36cc5e718a0a@aklaver.com> In-Reply-To: From: Igor Korot Date: Sat, 7 Dec 2024 17:58:39 -0600 Message-ID: Subject: Re: Insert records in the tavke only if they are not exist To: Adrian Klaver , "pgsql-generallists.postgresql.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, Adrian, On Sat, Dec 7, 2024 at 5:07=E2=80=AFPM Adrian Klaver wrote: > > On 12/7/24 12:17, Igor Korot wrote: > > Hi, Adrian, > > > > On Sat, Dec 7, 2024 at 12:32=E2=80=AFPM Adrian Klaver wrote: > >> > >> On 12/7/24 09:59, Igor Korot wrote: > >>> Hi, Adrian, > >>> > >>> On Sat, Dec 7, 2024 at 11:18=E2=80=AFAM 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 re= cords > >>>>> in them. > >>>>> > >>>>> When the app starts for the second time it should check if the tabl= es > >>>>> 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. Good.. > > > > > 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? I am making the tables and naming them with a specific pattern. Now I'm curious - if I start psql and will want to create a table named pg_am, what will happen? I presume psql will produce error saying that the system table with that name exists and the user can't create ome. Am I right? > > > 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? My tables are named with the specific pattern. Also - see above. > > How do you get these changes to play nice with the existing structure? Again - not sure what you mean here.... > > > 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. If one of my tables will be dropped - it will be re-created. I'm using CREATE TABLE IF NOT EXIST. > > > > All records that were there are staying unchanged. > > INSERT/UPDATE against your tables is not a possibility? It is.. All I;m saying that when the app starts-up, this is done automatically And if the user decides to insert some data - that's on him > > > 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? Correct. > > 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? I don't. Think about MS ACCESS-like applications. ACCESS creates the internal tables to keep track of some internals. Is there a possibility of a clash with the user table? Ofc there is. But MS is still doing it nevertheless, because chances of this occurring are really slim. And if a user acquire access to those internal tables and start modify them and in the process screw something up, well he uses MS product as a developer and so should know better as a developer And if MS can do it - why can't I? > > > > > 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. What is considered correct outcome is strongly on user if we are talking about my app. > > > >> 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. But not to me. My application targets developers, not end users. Thank you. > > > > >> > >> > >>> > >>> Thank you. > > -- > Adrian Klaver > adrian.klaver@aklaver.com >