public inbox for [email protected]  
help / color / mirror / Atom feed
From: Tom Lane <[email protected]>
To: David G. Johnston <[email protected]>
Cc: H <[email protected]>
Cc: PostgreSQL Users Mailing List <[email protected]>
Subject: Re: Combining metavariables and table names
Date: Sun, 28 Dec 2025 22:41:19 -0500
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAKFQuwb9jdGH6-og4HFQv=AU7UH+V2AjoQy2y+xZ_Cjz1bx5FA@mail.gmail.com>
References: <[email protected]>
	<CAKFQuwb9jdGH6-og4HFQv=AU7UH+V2AjoQy2y+xZ_Cjz1bx5FA@mail.gmail.com>

"David G. Johnston" <[email protected]> writes:
> On Sunday, December 28, 2025, H <[email protected]> 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






view thread (4+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected]
  Subject: Re: Combining metavariables and table names
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox