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.
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 from stdin : ' :my_user
The COPY command can, perhaps, help interaction with stdin,
COPY t(a) FROM stdin;
This example do the same as
\prompt 'Please, enter a string ', mystr
insert into t(a) values ( ':mystr' );
with less confusion with quotes, and the possibility of do a massive inputing task.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With