title: Postgresql : null values cannot be formatted as an SQL identifier
body: <p>how to resolve this <code>ERROR: null values cannot be formatted as an SQL identifier</code> when trying to select my function:</p>
  <pre><code>select ws_sls_core.ars_pricing_test()
  ERROR:  null values cannot be formatted as an SQL identifier
  CONTEXT:  SQL statement &quot;select string_agg(distinct format('(props -&gt;&gt; %L) as %I', w_order_line_d.matl_grp2_desc, w_order_line_d.matl_grp2_desc), ', ')
                         from ws_sls_core.w_support_pricing_d 
      left join ws_sls_core.w_order_line_d 
      on w_support_pricing_d.svc_pricing_type = w_order_line_d.matl_grp2_cd&quot;
  PL/pgSQL function ars_pricing_test() line 6 at SQL statement
  </code></pre>
  <p>I have checked and the query in use doesn't produce any NULL</p>
  <pre><code>select * from ws_sls_core.w_support_pricing_d where svc_pricing_type is
    null
  </code></pre>
  <p>I have tried the below-mentioned code without JOIN and it works fine, I need an additional column and have to use join, and I am only seeing this error.</p>
  <p>Here is my complete code</p>
  <pre><code>CREATE OR REPLACE FUNCTION ws_sls_core.ars_pricing_test(
      )
  RETURNS boolean
      LANGUAGE 'plpgsql'
      COST 100
      VOLATILE 
  AS $BODY$
  declare
    l_sql text;
    l_columns text;
  begin
      select string_agg(distinct format('(props -&gt;&gt; %L) as %I', w_order_line_d.matl_grp2_desc, w_order_line_d.matl_grp2_desc), ', ')
      into l_columns
      from ws_sls_core.w_support_pricing_d 
      left join ws_sls_core.w_order_line_d 
      on w_support_pricing_d.svc_pricing_type = w_order_line_d.matl_grp2_cd;
  --     and A.svc_pricing_type is not null;
    
    l_sql := 
      'create or replace view ars_pricing_test as 
       select w_support_pricing_d.item_num, '||l_columns||' 
       from (
        select w_support_pricing_d.item_num, json_object_agg(w_order_line_d.matl_grp2_desc,w_support_pricing_d.mnth_maint_price) as props
         from ws_sls_core.w_support_pricing_d 
          left join ws_sls_core.w_order_line_d 
          on w_support_pricing_d.svc_pricing_type = w_order_line_d.matl_grp2_cd
         group by w_support_pricing_d.item_num 
       ) t';
    execute l_sql;
    return true;
  end;
  $BODY$;
  
  ALTER FUNCTION ws_sls_core.ars_pricing_test()
  </code></pre>