Re: Combining metavariables and table names

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: H <agents(at)meddatainc(dot)com>
Cc: PostgreSQL Users Mailing List <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Combining metavariables and table names
Date: 2025-12-30 01:17:37
Message-ID: CAKFQuwY5UK0YFi2yE1TBigQDK+Mh=jjzDfh9CLhPvNxN3e2nLA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Dec 29, 2025 at 5:58 PM H <agents(at)meddatainc(dot)com> wrote:

> Just tried your suggestion to use format() but it resulted in a 'syntax
> error at or near "("'
>

Helps to show exactly what you tried. I provided pseudo-code.

postgres=# \set sch 'schemaname'
postgres=# select format('%I.%I', :'sch', 'tblname');
format
--------------------
schemaname.tblname
(1 row)

Admittedly, if the names do require quoting, and depending on how the
function uses the value, some additional tweaking may be required.

There shouldn't be anything you cannot do with format that you can do with
pre-processing and setting the variable up-front. Admittedly that is
probably cleaner overall anyway though.

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message H 2025-12-30 03:02:20 Re: Combining metavariables and table names
Previous Message H 2025-12-30 01:01:21 Re: Combining metavariables and table names