May we interact with a psql script?
Can we do something like
\echo 'Type username to show its properties';
SELECT * FROM mY开发者_如何学Go_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.
Would substitution variables accomplish what you need?
http://www.oracle.com/technology/support/tech/sql_plus/htdocs/sub_var.html
加载中,请稍侯......
精彩评论