Re: Using Substitution Variables In PostgreSQL

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Osahon Oduware <osahon(dot)gis(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Using Substitution Variables In PostgreSQL
Date: 2017-10-16 14:27:17
Message-ID: CAKFQuwZwCipipH=gsO=pYiyUiH+CFRsLK+oaeT4YRuLeSWy+tA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Oct 16, 2017 at 7:08 AM, Osahon Oduware <osahon(dot)gis(at)gmail(dot)com>
wrote:

> Hi All,
>
> I wanted to find out how to use a substitution variable in an SQL
> statement that would cause the user to be prompted for a value. Something
> similar to the ampersand (&&) in ORACLE.
>
> For example, given the SQL statement below:
> SELECT <col1>,<col2>,<col3>
> FROM <table>
> WHERE <col5> = 35
>
> I want the user to be prompted for the value in the WHERE (filter) clause,
> e.g.
> SELECT <col1>,<col2>,<col3>
> FROM <table>
> WHERE <col5> = ?
>
> I would be glad if someone could point me in the right direction.
>

​That would be a client-side feature. The only client supported on this
list is psql. psql does not have this capability. It does have the
"\prompt" ​meta-command which will serve in this specific case.

\prompt 'Enter a value for varname' varname

SELECT ... WHERE <col5> = :'varname';

https://www.postgresql.org/docs/10/static/app-psql.html

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message said assemlal 2017-10-16 14:43:05 could not fdatasync log file: Input/output error
Previous Message Achilleas Mantzios 2017-10-16 14:23:44 Re: Using Substitution Variables In PostgreSQL