KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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.
Tags (comma-separated)
Save Edits
Cancel