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 1tJz6P-006BMk-OH for pgsql-general@arkaria.postgresql.org; Sat, 07 Dec 2024 18:00:25 +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 1tJz6M-00GHEb-65 for pgsql-general@arkaria.postgresql.org; Sat, 07 Dec 2024 18:00:23 +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 1tJz6L-00GHET-OV for pgsql-general@lists.postgresql.org; Sat, 07 Dec 2024 18:00:23 +0000 Received: from mail-yb1-xb2a.google.com ([2607:f8b0:4864:20::b2a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tJz6K-001Xv3-07 for pgsql-general@lists.postgresql.org; Sat, 07 Dec 2024 18:00:22 +0000 Received: by mail-yb1-xb2a.google.com with SMTP id 3f1490d57ef6-e3a26de697fso364848276.3 for ; Sat, 07 Dec 2024 10:00:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733594418; x=1734199218; 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=8FLLNvbxqMZh9mHpyDUdLFfUMpniPC+po2aa+uTWRYI=; b=Un46nm7jH5QgAVHF223MVnZpxfs6A2XKccSbd8K7DIpP8cOuIA2tt1nPEtzWvsLDDx 8qgYm0C1Nc8LNHFtdWtDyVmgTMt3DKCiEPMDNkESsGqdM9PV/OT8T99ZEzSt/65flGw6 +BIdLvsBIbRVY44ttV4QXt7uZ5XUgciyxuIsaOZ23PnteNCF0TWNWK+tMOQVJF6LQDZJ V5ebdn3uhGtkvEZIWVKWhXINhDCOf0CxzBT5+FqdAdLYzg2zZZ4enyNJvJ7DdoYImLDr rkgMHiiZIKhza4DWN3KjhCori4aEB2STiyBJq4Dm5y1HVIK6w7hh2jzhXh0dKfxU9kuc 9kGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733594418; x=1734199218; 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=8FLLNvbxqMZh9mHpyDUdLFfUMpniPC+po2aa+uTWRYI=; b=NSwY+OD0X+6MfmXKI2PazhBQkXdGZyFyUot5udS886c9YQAmr1SzcVme88VDb/rK2I b56GDLSRzzPp7FQtiwMZTEEckk59VqoHFXRfHnzVAdVITryzCl8RJ0Vtunk7oaXL39Ge 3Pl7xDnKbda4fhKBP8oucHV0FZaSVdFAgZRdm63bk4mJ8znkqTII5YkKVmnGd901PORb zbN9rMEdHpZMJpN/3IKSpeKMGZdeo1vW81lzB/IJAiCrIy+jOsP+FodPGhYHc6NMC8bM CI/ro/IuO68c32/Hi4B+adnemvBaKMYJOWVbtff4rKPXY93gS5lbqiL4zDoRS26KpYVA wxXw== X-Forwarded-Encrypted: i=1; AJvYcCWjotTxMrTE7d0KXTZSIYyZlEj6hZlffv8OzQOFwd43J/+he/KUhmHzt0OukvsxP5QDPtiNW+Xvm/nH9x1e@lists.postgresql.org X-Gm-Message-State: AOJu0YzbRkKYXLonjWWthYsH6HpLNHLYDZP2buVbMUe+mSwmsDK3q9DM 35Sb8krk3Gt3DkqNy2+XTrFC4n5h07stLosVHW/EOSuylA/d8AtEP+pu4MWlUUBZJX0rx/zm1ZQ Zo7pywG1JJEp3K9gUGcTIbPL/sNgCnDG9 X-Gm-Gg: ASbGnctVXkBMwgG9/d20S+VA1sR493BehTm4kiT2CrzMKsv2Z1sJ9dD5yZgdLsBIN+o h5EZnXNpECtI2vxNY32vRLrXzWYjiyvw+8L1m0xL0ULiPrGWl708v4PLz3RrrXGEj X-Google-Smtp-Source: AGHT+IFdjDXGiweYtnXbW5mXCwQhenP1+NJn+OxB8OQyIt8OX526riy/zrttcU6OGNxkyo0J1lBN4BOLt8TvNiEvjrw= X-Received: by 2002:a05:6902:2388:b0:e39:83a4:9240 with SMTP id 3f1490d57ef6-e3a0b472f8amr5340718276.42.1733594418526; Sat, 07 Dec 2024 10:00:18 -0800 (PST) MIME-Version: 1.0 References: <8770b693-0c44-40de-b883-36cc5e718a0a@aklaver.com> In-Reply-To: <8770b693-0c44-40de-b883-36cc5e718a0a@aklaver.com> From: Igor Korot Date: Sat, 7 Dec 2024 11:59:56 -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 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 record= s > > 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. > > 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 index and will not do anything if the recrd with such data on the index already exists. > > > > > 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. Thank you. > > > > > I can run this inside transaction, but will this be enough? Will statin= g > > transaction lock the DB and the second user will wait for transaction t= o > > complete? > > > > Thank you. > > > > -- > Adrian Klaver > adrian.klaver@aklaver.com >