在.sql文件Postgres中打印到屏幕 [英] Printing to screen in .sql file postgres

查看:420
本文介绍了在.sql文件Postgres中打印到屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

听起来这应该是一件很容易的事,但是,我找不到任何方法。

This sounds like it should be a very easy thing to do, however, I cannot find ANYWHERE how to do it.

我有一个.sql文件

我想在每个命令完成之后写到屏幕上。升级我的应用程序以更改表,插入/更新等。

I want to write to the screen after every command finishes.

例如,如果我有以下内容:

So, for instance if I have something like:

insert into X...

我想看到类似


开始插入表X

已完成插入表X

在Postgres中可能吗?

Is this possible in Postgres?

推荐答案

如果您只是向 psql ,那么您有几个选择。

If you're just feeding a big pile of SQL to psql then you have a couple options.

您可以运行 psql -echo-all


-a

-echo -all

读取
时,将所有输入行打印到标准输出中。这比交互式
模式对脚本处理更有用。这等效于将变量 ECHO 设置为 all

该选项和其他回显此类型的所有内容选项(请参见手册)可能太吵了。如果只想手动打印东西,请使用 \echo

That and the other "echo everything of this type" options (see the manual) are probably too noisy though. If you just want to print things manually, use \echo:


\echo 文本 [...]

打印标准输出的参数,以空格分隔,后跟换行符。这对于在脚本输出中散布信息很有用。

\echo text [ ... ]
Prints the arguments to the standard output, separated by one space and followed by a newline. This can be useful to intersperse information in the output of scripts.

所以您可以说:

\echo 'Starting to insert into table X'
-- big pile of inserts go here...
\echo 'Finished inserting into table X'

这篇关于在.sql文件Postgres中打印到屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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