Does PostgreSQL have a feature like 'Ampersand Substitution' in SQL*Plus?

39 Views Asked by At

While 'Ampersand Substitution' is not a part of Oracle Database DBMS and is a feature of SQL*Plus, I am interested whether some tool related to PostgreSQL of PostgreSQL itself has the same feature.

Ampersand Substitution looks in the following way in SQL*Plus:

I run a script like this:

SELECT * FROM my_table WHERE col1 = '&value';

When executed in SQL*Plus, this statement must prompt me for the value used in the query.

I tried to find the answer in the Internet, but I had found just a few unanswered questions similar to mine. Maybe someone knows whether it is possible in PostgreSQL to make the user to input some values used in the query during the script's runtime? Thank you in advance!

1

There are 1 best solutions below

0
Laurenz Albe On BEST ANSWER

The command line client psql has functionality like that:

test=> \prompt 'Tell me your name: ' name
Tell me your name: Laurenz
test=> SELECT 'Hello ' || :'name';
   ?column?    
---------------
 Hello Laurenz
(1 row)