views:

37

answers:

2

Can we do something like

\echo 'Type username to show its properties';
SELECT * FROM mY_users WHERE username = ?;
\echo 'End of script';

in a psql script file ?

The system would wait until we enter something then echo the 'End of script' string.

A: 

Would substitution variables accomplish what you need?

http://www.oracle.com/technology/support/tech/sql_plus/htdocs/sub_var.html

dmags
psql is for postgresql.
Luc M
A: 

I just realized that internal doesn't mean variable defined into postgresql.conf.

So, I can use \prompt

\prompt 'Please, enter an username ', my_user
SELECT * FROM mY_users WHERE username = :my_user;
\echo 'End of script'  

EDIT

Like command \echo, you don't need to add a ; at the end. In fact, if you add one when using \prompt, you get an error.

You can show use the value read from the stdin.

\echo 'Here\'s the value read form stdin : ' :my_user
Luc M