title: PostgreSQL: Select string_agg into variable
body: <p>I have a string to execute with the string aggregate function within the postgresql function. Here is the following script for that.  </p>
  
  <p><strong>Example</strong>:</p>
  
  <pre><code>create or replace function f(colvalue int,colnvalue varchar)
  returns void as
  $$
  declare
        sql varchar;
        var varchar;
  begin
       sql := 'Select var:= string_agg(................) /* Error occurred here near var:= */
               from tablename where cola ='|| colvalue || ' AND coln ='|| colnvalue;
  
       raise notice '%'sql;
  
       execute sql into var;
  
       raise notice var;
  
  end;
  $$
  language plpgsql;
  </code></pre>
  
  <p><strong>Error</strong>: </p>
  
  <pre><code>ERROR:  syntax error at or near ":="
  </code></pre>
  
  <p><strong>Note</strong>: I want the result of <code>string_agg</code> into <code>var</code>.</p>