postgresql – 被遗忘的赋值运算符“=”和普通的“:=”

PL / pgsql的文档说,声明和赋值给变量是:=。
一个简单,更短,更现代(看脚注)=似乎工作正如预期:
CREATE OR REPLACE FUNCTION foo() RETURNS int AS $$
    DECLARE
      i int;
    BEGIN
      i = 0;  
      WHILE NOT i = 25 LOOP
          i = i + 1;
          i = i * i;
      END LOOP;
      RETURN i;
    END;
    $$ LANGUAGE plpgsql;

    > SELECT foo();
    25

请注意,Pl / pgsql可以清楚地区分赋值和比较,如图所示

WHILE NOT i = 25 LOOP

所以,问题是:

>我没有在文档中找到提及和/或解释这一点的一些部分?
>有没有任何已知的后果使用=而不是:=?

编辑/脚注:

请采取“更现代”的部分与眨眼像A Brief,Incomplete,and Mostly Wrong History of Programming Languages

1970 – Niklaus Wirth creates Pascal,a procedural language. Critics
immediately denounce Pascal because it uses “x := x + y” Syntax
instead of the more familiar C-like “x = x + y”. This criticism
happens in spite of the fact that C has not yet been invented.

1972 – Dennis Ritchie invents a powerful gun that shoots both forward
and backward simultaneously. Not satisfied with the number of deaths
and permanent maimings from that invention he invents C and Unix.

在PL / Pgsql解析器中,赋值运算符被定义为
assign_operator : '='
                | COLON_EQUALS
                ;

这是一个未记录的旧功能。至少自1998年以来在Postgresql代码中。
它计划被删除,但仍然保持,因为有些人依赖它。

查看Tom Lane的消息(核心Pg开发人员):
http://archives.postgresql.org/pgsql-bugs/2011-08/msg00140.php

首先介绍一下(根据官方Git仓库):
http://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=863a62064cfc2b706dd6ab45487d15cc33cedb35

所以,直接回答你的问题:

Didn’t I find some section in the docs which mention and/or explains
this?

你没有找到它,因为它是无证的,不应该依赖。

Are there any kNown consequences using = instead of :=.

使用=没有任何副作用,但是你应该使用:=作为赋值,使你的代码面向未来。

更新:在罕见的情况下可能会有副作用(见Erwin的回答)

UPDATE(2015年6月):正如Daniel指出的,截至Postgresql 9.4 it is documented.这个特性可能会比我预期的更长。这可能不仅是一个遗留功能,而且还是PL / sql兼容性。

相关文章

项目需要,有个数据需要导入,拿到手一开始以为是mysql,结果...
本文小编为大家详细介绍“怎么查看PostgreSQL数据库中所有表...
错误现象问题原因这是在远程连接时pg_hba.conf文件没有配置正...
因本地资源有限,在公共测试环境搭建了PGsql环境,从数据库本...
wamp 环境 这个提示就是说你的版本低于10了。 先打印ph...
psycopg2.OperationalError: SSL SYSCALL error: EOF detect...