Re: Combining metavariables and table names - Mailing list pgsql-general

From Tom Lane
Subject Re: Combining metavariables and table names
Date
Msg-id 2743391.1766979679@sss.pgh.pa.us
Whole thread Raw
In response to Re: Combining metavariables and table names  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: Combining metavariables and table names
List pgsql-general
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Sunday, December 28, 2025, H <agents@meddatainc.com> 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



pgsql-general by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: Combining metavariables and table names
Next
From: Ron Johnson
Date:
Subject: psql: print values and return the COUNT(*) value to bash?