在pl/pgsql中,有没有RAISE计算的方法?

In pl/pgsql, is there a way to RAISE calculations?

我正在尝试测试一些代码,如果有一种方法可以 RAISE NOTICE 就像我使用 print()console.log().

这是我的尝试,但不确定它是如何工作的:

DO
$cols$
DECLARE
    qty_cols INT := 3;
    current_month INT := ( SELECT EXTRACT(MONTH FROM DATE(NOW())) );
    month_col INT;
BEGIN
    FOR month_col IN 1..qty_cols LOOP
        IF current_month < (month_col+1) THEN
            --RAISE NOTICE (12+current_month) - month_col;
            RAISE NOTICE '%', (12+current_month) - month_col;
        ELSE
            --RAISE NOTICE (current_month - month_col);
            RAISE NOTICE '%', (12+current_month) - month_col;
        END IF;
    END LOOP;
END
$cols$;

我知道我可以使用 % 符号来替换变量,但这似乎不仅仅是替换成一个变量...

RAISE NOTICE 期望后面的参数是带有 % 占位符的格式字符串,随后的参数将被放入其中。后面的参数可以是计算

After level if any, you can write a format (which must be a simple string literal, not an expression). The format string specifies the error message text to be reported. The format string can be followed by optional argument expressions to be inserted into the message. Inside the format string, % is replaced by the string representation of the next optional argument's value. Write %% to emit a literal %. The number of arguments must match the number of % placeholders in the format string, or an error is raised during the compilation of the function.

单个后续参数的格式字符串至少应如下所示:

RAISE NOTICE '%', (12+current_month) - month_col;

虽然意图可能更具描述性:

RAISE NOTICE 'The month difference is %', (12+current_month) - month_col;