我们可以与psql脚本进行交互吗? [英] May we interact with a psql script?

查看:81
本文介绍了我们可以与psql脚本进行交互吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以做类似的事情

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

在psql脚本文件中吗?

in a psql script file ?

系统将一直等到我们输入内容,然后回显脚本结束字符串。

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

推荐答案

我刚刚意识到内部函数没有作用 t是定义在postgresql.conf中的变量。

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

因此,我可以使用 \提示

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






EDIT


EDIT

就像命令\echo一样,您无需在最后添加; 。实际上,如果在使用 \提示时添加一个,则会出现错误。

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.

您可以显示use

\echo 'Here\'s the value read from stdin : ' :my_user

这篇关于我们可以与psql脚本进行交互吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆