英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论