Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6637215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:17:08+00:00 2026-05-25T23:17:08+00:00

The documentation for PL/pgSQL says, that declaration and assignment to variables is done with

  • 0

The documentation for PL/pgSQL says, that declaration and assignment to variables is done with :=.
But a simple, shorter and more modern (see footnote) = seems to work as expected:

    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

Please note, that Pl/pgSQL can distinguish assignment and comparison clearly as shown in the line

      WHILE NOT i = 25 LOOP

So, the questions are:

  • Didn’t I find some section in the docs which mention and/or explains this?
  • Are there any known consequences using = instead of :=?

Edit / Footnote:

Please take the “more modern” part with a wink like in 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:17:08+00:00Added an answer on May 25, 2026 at 11:17 pm

    In PL/PgSQL parser, assignment operator is defined as

    assign_operator : '='
                    | COLON_EQUALS
                    ;
    

    This is a legacy feature, present in source code since 1998, when it was introduced – as we can see in the PostgreSQL Git repo.

    Starting from version 9.4 it is oficially documented.

    This idiosyncrasy – of having two operators for same thing – was raised on pgsql users list, and some people requested it to be removed, but it’s still kept in the core because fair corpus of legacy code relies on it.

    See this message from Tom Lane (core Pg developer).

    So, to answer your questions straight:

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

    You did not find it because it was undocumented, which is fixed as of version 9.4.

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

    There are no side consequences of using =, but you should use := for assignment to make your code more readable, and (as a side effect) more compatible with PL/SQL.

    Update: there may be a side consequence in rare scenarios (see Erwin’s answer)


    UPDATE: answer updated thanks to input from Daniel, Sandy & others.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Documentation says that waypoints limit is 8 points. But I have to draw a
Documentation says that waypoints limit is 8 points. But I have to calculate a
The documentation lists the tags that are allowed/removed by default: http://www.feedparser.org/docs/html-sanitization.html But it doesn't
The documentation for NSDictionary says that the method objectForKey returns nil if the NSDictionary
Python documentation says that os.rename(src, dst) ... On Windows, if dst already exists, OSError
The documentation , implies that the connection is always remotely available, but since I
The documentation says there's a limit to the number of regions that can be
The documentation says that the cartesian product function the actual implementation does not build
Documentation for logging module says that If you are implementing asynchronous signal handlers using
The documentation for libev ( source ) says that: Kqueue deserves special mention, as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.