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.96) (envelope-from ) id 1va48L-0038EI-1G for pgsql-general@arkaria.postgresql.org; Mon, 29 Dec 2025 03:41:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1va48J-00FMCO-0a for pgsql-general@arkaria.postgresql.org; Mon, 29 Dec 2025 03:41:23 +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.96) (envelope-from ) id 1va48I-00FMCF-2l for pgsql-general@lists.postgresql.org; Mon, 29 Dec 2025 03:41:23 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1va48H-0037I5-33 for pgsql-general@lists.postgresql.org; Mon, 29 Dec 2025 03:41:22 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 5BT3fJ3p2743392; Sun, 28 Dec 2025 22:41:19 -0500 From: Tom Lane To: "David G. Johnston" cc: H , PostgreSQL Users Mailing List Subject: Re: Combining metavariables and table names In-reply-to: References: <8254F175-871C-4678-8D28-A67E09B099A6@meddatainc.com> Comments: In-reply-to "David G. Johnston" message dated "Sun, 28 Dec 2025 18:53:50 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2743390.1766979679.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Sun, 28 Dec 2025 22:41:19 -0500 Message-ID: <2743391.1766979679@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > On Sunday, December 28, 2025, H wrote: >> I have a feeling I might be missing how to use the combination of a >> metavariable and a table name when used in an argument to a procedure. > No, what you are doing is impossible if you limit yourself to direct SQL > command syntax writing. Yeah :-( > I’d probably do something like: > versioning(…, format(‘%I.%I’, :’s’, ‘test_history’), …) The reason this is hard is that we don't support expressions in CREATE TRIGGER, only simple literals. So any such processing would have to be done in the client-side code that is sending the command, and I don't think psql's variable-substitution ability is quite up to the job. You might be able to make it work through the hacky method of supplying the schema name and table name as separate trigger arguments. Another idea could be to construct the desired string as a SELECT result, and then use \gexec. There's a few too many moving parts in that for my taste, but maybe it could work. regards, tom lane