pl/pg 语言运行中输出信息

本文介绍PostgreSQL中PL/pgSQL语言如何使用RAISE语句来报告消息及引发错误。通过设置不同级别,可以生成不同优先级的消息,并且可以通过配置变量控制消息的输出方式。文中还提供了具体的示例来展示如何使用RAISE语句。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

官方文档:http://www.postgresql.org/docs/8.1/static/plpgsql-errors-and-messages.html

 

Use the  statement to report messages and raise errors.

RAISE  '' [,  [, ...]];

Possible levels are , , , , , and .  raises an error (which normally aborts the current transaction); the other levels only generate messages of different priority levels. Whether messages of a particular priority are reported to the client, written to the server log, or both is controlled by the log_min_messages and client_min_messages configuration variables. See Chapter 17 for more information.

Inside the format string,  is replaced by the next optional argument's string representation. Write  to emit a literal . Arguments can be simple variables or expressions, and the format must be a simple string literal.

In this example, the value of  will replace the  in the string:

RAISE NOTICE 'Calling cs_create_job(%)', v_job_id;

This example will abort the transaction with the given error message:

RAISE EXCEPTION 'Nonexistent ID --> %', user_id;

 presently always generates the same SQLSTATE code, , no matter what message it is invoked with. It is possible to trap this exception with  but there is no way to tell one  from another.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值