PostgreSQL:在psql中使用RAISE NOTICE时,我能否避免输出中的”NOTICE:”前缀?

huangapple go评论60阅读模式
英文:

PostgreSQL : when using RAISE NOTICE in psql, can I avoid the "NOTICE :" prefix from the output

问题

我正在尝试将一些功能从Oracle PL/SQL迁移到PostgreSQL PL/pgSQL。

由于它似乎是在屏幕上打印文本的最常见方式,我想使用RAISE NOTICE来在标准输出上显示消息,这些消息将使用psql的**-o file.txt**参数输出到文件。

问题是消息级别(这里是RAISE NOTICE 'msg' => level: NOTICE)出现在消息之前(前缀),我不喜欢这样。

例如,当在psql中运行此PL/pgSQL代码时:

DO $$
BEGIN
  RAISE NOTICE 'my message';
END; $$;

将生成此输出:

NOTICE: my message

是否有办法在消息本身之前删除消息级别?
(在这里,我想要避免“NOTICE:”前缀)。

附注:我已经看到了这个帖子,其中在psycopg2的上下文中提出了同样的问题,但在这里我的上下文是psql工具。

还有这个其他帖子接近我在这里尝试做的事情,但答案对我来说不令人满意。

注意:我正在使用最新的PostgreSQL和psql(版本12.1)。

英文:

I am trying to port some functionalities from Oracle PL/SQL to PostgreSQL PL/pgSQL.

As it seems to be the most common way of printing text to screen, I would like to use the RAISE NOTICE to display messages on the standard output, output that would go to a file using -o file.txt argument of psql.

Problem is that the message level (here RAISE NOTICE 'msg' => level : NOTICE) goes before the message in the output (prefix) and I don't like it.

E.g. this PL/pgSQL code when run in psql :

DO $$
BEGIN
  RAISE NOTICE 'my message';
END; $$;

will generate this output :

NOTICE:  my message

Is there any way to remove the message level before the message itself ?
(here I would like to avoid "NOTICE :" prefix).

PS : I have seen this post where the same question is asked in the context of psycopg2, but here my context is the psql tool.

Also this other post is close to what I'm trying to do here but the answer is not satisfying to me.

NB: I'm using latest PostgreSQL and psql (version 12.1).

答案1

得分: 2

不能。这是libpq - Postgres 驱动程序的行为,psql 使用这个驱动程序。

英文:

No, you cannot. This is the behaviour of libpq - Postgres driver, and psql uses this driver.

huangapple
  • 本文由 发表于 2020年1月3日 18:40:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/59577093.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定