Re: How to pass arguments in postgres to sql scripts.

From: Feike Steenbergen <feikesteenbergen(at)gmail(dot)com>
To: kunwar singh <krishsingh(dot)111(at)gmail(dot)com>
Cc: pgsql-sql(at)lists(dot)postgresql(dot)org
Subject: Re: How to pass arguments in postgres to sql scripts.
Date: 2024-05-03 16:43:42
Message-ID: CAK_s-G0DXgxRJHbhcaUFyBi5+CW-C9J2u-m8RXWsw9CB=q6YvA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sat, 27 Apr 2024 at 15:03, kunwar singh <krishsingh(dot)111(at)gmail(dot)com> wrote:
>
> Hi friends, Question: How to pass arguments in postgres to sql scripts. Context. When I am monitoring my production Oracle databases I have a lot of simple sql scripts (which require one or more arguments) which make my monitoring/troubleshooting life simpler. How can I achieve the same in postgres? We are migrating our Oracle databases to Postgres and I am modifying my scripts to do the same in Postgres.

One way to do it is with --set

$ psql --set var1=postgres -AtXq
postgres=# select pid from pg_stat_activity where usename=:'var1';
185
1939

Kind regards,

Feike Steenbergen

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bo Guo 2024-05-14 11:11:56 Small table selection extremely slow!
Previous Message Nic Mitchell 2024-05-02 22:47:46 Re: One parent record with 3 possible child records