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 1tK5Ul-006onu-TS for pgsql-general@arkaria.postgresql.org; Sun, 08 Dec 2024 00:50:00 +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 1tK5Ui-000JFE-OO for pgsql-general@arkaria.postgresql.org; Sun, 08 Dec 2024 00:49:57 +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 1tK5Uh-000JEy-7w for pgsql-general@lists.postgresql.org; Sun, 08 Dec 2024 00:49:57 +0000 Received: from fout-a1-smtp.messagingengine.com ([103.168.172.144]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tK5Uf-001a9B-E6 for pgsql-general@lists.postgresql.org; Sun, 08 Dec 2024 00:49:55 +0000 Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfout.phl.internal (Postfix) with ESMTP id 6E3341382E12; Sat, 7 Dec 2024 19:49:52 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Sat, 07 Dec 2024 19:49:52 -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=1733618992; x=1733705392; bh=GCq+kdOkwnDRMZNz/ym9LEvQlutnl7nG9G4n3s1OowI=; b= akGaFx3ju3gnVi89PftNouHyylJCahxRZP2jB/cOavhS4AH1jwNbxhXXHfwgPcr6 +Hgsy3xLcjosdu1t7gv8qwscx2dvNGMLMtt1oPei8iP0w5M8FjRzrGHa4BskzTST q+nYDKo5nqh2hrYImQfdeZBgiCEUh7NPVlr48xPv6goNZ+BV1AXoX5qzqQzjKr+j VAQ0YaVPANoqn6yuI9xhVkhP+JpiX5xpAGFQhUQXNF1fgn37XBpBaEz6rBbG8f2p ML3fW9skf4lIecBRN98qZy17lMdgol837wxJ81b1davUht3HaYFOOoAgv7fxCoyV y2lLuI+pSIqEVa3pOX5CMQ== 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=1733618992; x=1733705392; bh=G Cq+kdOkwnDRMZNz/ym9LEvQlutnl7nG9G4n3s1OowI=; b=phW2VOxiRg26FokfU r851xxw6PMz/Z/s8CPxrpQ70k+HPCt5qYYcoTJSgGQ5CYRIu/vym2j6P1ICueKf5 JRFREO4AAldLf8MTmbNFhxG2jolsj76YVCTvw8yA2BzwY9DQh4SCb27qx0qAcWDx ufu13PVubRBjOGyhWk+5jWJbY6O4JT37J1HLb4fpumm4yDVGHJwwkNoGfmKFu7qN Ij75enSKSyYMHVF4z5aJcz1bfZTyGQ0SZNGjtXJYQuTFibsYMOQn0QVVtLtH6//j CQhLJM5M5htR6Vufe0kmBBH8sGKrYY/vbqJoKmoWpfsdZIv7QuodRYyfbhWrA5Px XRSUw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrjedvgddvhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtjeertddtvdejnecu hfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrg hklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepiedvhfeiheehgeeuieeljeei tedtjeehudegfeelkedvleekhedtgfeiffefkedunecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgr vhgvrhdrtghomhdpnhgspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtg hpthhtohepihhkohhrohhttddusehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhq lhdqghgvnhgvrhgrlheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 7 Dec 2024 19:49:51 -0500 (EST) Message-ID: <1d31bc1f-78da-40a5-8d4c-57feab73da15@aklaver.com> Date: Sat, 7 Dec 2024 16:49:50 -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: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12/7/24 15:58, Igor Korot wrote: > Hi, Adrian, > >> 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? When you refer to psql are you talking about the CLI program or the Postgres server in general? As to table names it depends. A schema is a namespace so if you put the table in it's own schema then the server will not complain: create table test_sch.pg_am(id integer); CREATE TABLE \d *.pg_am Table "pg_catalog.pg_am" Column | Type | Collation | Nullable | Default -----------+---------+-----------+----------+--------- oid | oid | | not null | amname | name | | not null | amhandler | regproc | | not null | amtype | "char" | | not null | Indexes: "pg_am_oid_index" PRIMARY KEY, btree (oid) "pg_am_name_index" UNIQUE CONSTRAINT, btree (amname) Table "test_sch.pg_am" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+--------- id | integer | | | I would strongly advise against this naming schema for the above reason. > >> >>> 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. Yes, but if you allow users into the database: a) They can figure out what that pattern is. b) Mess with the tables. > >> >> How do you get these changes to play nice with the existing structure? > > Again - not sure what you mean here.... Examples: 1) A user creates table that creates a FK relationship to one of 'your' tables and you then change 'your' table and invalidate that relationship. 2) A user changes the structure of 'your' tables. > If one of my tables will be dropped - it will be re-created. > I'm using CREATE TABLE IF NOT EXIST. This means every time the app is run it could potentially run one or more schema/data migrations. How are you going to track the state of the database in order to get it back to what it was when the change or changes occurred? > >> >> >>> 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 Again, using what point in time state? > > And if the user decides to insert some data - that's on him No the point of this thread is it's on you or you would not be asking how to restore to a known state. >> >> 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? Because MS has the lawyers to keep at bay anyone complaining that Access blew up their application. > > >> >>> >>> 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. Except you are asking how to deal with changes and so you are taking ownership of them. And in the case you describe, two different instances of the app making changes, how do you decide which one wins? >> 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. Who are users in your application. > > Thank you. > >> >>> >>>> >>>> >>>>> >>>>> Thank you. >> >> -- >> Adrian Klaver >> adrian.klaver@aklaver.com >> -- Adrian Klaver adrian.klaver@aklaver.com