Note that there are some explanatory texts on larger screens.

plurals
  1. POThe forgotten assignment operator "=" and the commonplace ":="
    text
    copied!<p>The documentation for PL/pgSQL says, that declaration and assignment to variables is done with <code>:=</code>. But a simple, shorter and <em>more modern</em> <sup>(see footnote)</sup> <code>=</code> seems to work as expected:</p> <pre><code> 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; &gt; SELECT foo(); 25 </code></pre> <p>Please note, that Pl/pgSQL can distinguish assignment and comparison clearly as shown in the line </p> <pre><code> WHILE NOT i = 25 LOOP </code></pre> <p>So, the questions are:</p> <ul> <li>Didn't I find some section in the docs which mention and/or explains this?</li> <li>Are there any known consequences using <code>=</code> instead of <code>:=</code>?</li> </ul> <p><strong>Edit / Footnote:</strong></p> <p>Please take the "more modern" part with a wink like in <a href="http://james-iry.blogspot.com/2009/05/brief-incomplete-and-mostly-wrong.html" rel="noreferrer">A Brief, Incomplete, and Mostly Wrong History of Programming Languages</a>:</p> <blockquote> <p>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.</p> <p>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.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload