在PL/PGSQL中,有没有办法提高计算?

发布于 2025-01-30 01:22:24 字数 698 浏览 3 评论 0原文

我正在尝试测试一些代码,如果有一种方法可以像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$;

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

I'm trying to test out some code, and it would be great if there was a way to RAISE NOTICE like i would with print() or console.log().

here is my attempt, but not sure how this works:

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$;

i know that i can use % symbols to replace variables, but this doesn't seem like just substituting into a variable...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

和我恋爱吧 2025-02-06 01:22:24

提高通知期望以下参数,该参数是具有占位符的格式字符串,将在其中放置后续参数。随后的论点可以是计算

在级别之后,您可以编写一个格式(必须是简单的字符串字面的,而不是表达式)。格式字符串指定要报告的错误消息文本。格式字符串可以遵循可选的参数表达式,要插入消息中。在格式字符串中,%被下一个可选参数值的字符串表示代替。写%%以发出字面百分比。参数的数量必须与格式字符串中的%占位符数量匹配,或者在函数的汇编过程中会增加错误。

最少的单个后续参数格式字符串看起来像:

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

尽管意图可能更具描述性:

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

RAISE NOTICE expects a following argument that is a format string with % placeholders, into which the subsequent arguments will be placed. The subsequent arguments can be calculations

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.

Minimally a format string for a single subsequent argument would look like:

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

Though the intent is perhaps to be more descriptive:

RAISE NOTICE 'The month difference is %', (12+current_month) - month_col;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文