Meaning of := in SQL

beniaminp picture beniaminp · Jan 9, 2015 · Viewed 13k times · Source

What does the := operator mean in SQL? I am using Postgresql and I have no idea what it means. I have this code :

DECLARE
  i RECORD;
  q TEXT[];
  cfg_rec RECORD;
BEGIN
  SELECT * FROM xxx_private.function() INTO cfg_rec;
  q:=q || cfg_rec.q;

Answer

Mureinik picture Mureinik · Jan 9, 2015

:= isn't an SQL operator. It's a PL/pgSQL operator (similar syntax can be found in PL1, Oracle's PL/SQL and even Pascal). Anyway, this is the assignment operator. In your case, it appends cfg_rec.q to the previous value of q (the || operator), and then assigns it back to the q variable you defined in the declare block.