title: PostgreSQL error - NullValueNotAllowed: query string argument of EXECUTE is null
body: <p>I try to execute the postgrsql function but run into an error during execution</p>
  <pre><code>DROP FUNCTION IF EXISTS weather_crup(jsonb);
  CREATE OR REPLACE FUNCTION weather_crup(
    input jsonb
  )
  RETURNS void
  LANGUAGE plpgsql
  AS $function$
  DECLARE
    _schema_nm character varying;
    _timezone text;
    _id bigint;
  BEGIN
  SELECT schema_name(l.data_owner_company_id),l.timezone 
   INTO _schema_nm,_timezone
  FROM locations l 
   WHERE l.guid = ((input-&gt;&gt;'siteGUID')::uuid)
  ;
  
  WITH input AS (
      SELECT 
        (a-&gt;&gt;'siteGUID')::uuid as _site_guid,
        (a-&gt;&gt;'diagnosticType') as dg_type,
        (a-&gt;&gt;'timeStamp')::timestamp at time zone _timezone at time zone 'UTC' as ts,
        (a-&gt;&gt;'value')::double precision as val
      FROM jsonb_array_elements(input) AS e(a)
    ),
  dev_ins as (
  INSERT INTO devices(
      data_owner_company_id, name, description,ext_supplier_id,device_type_id, unit_number)
      SELECT l.data_owner_company_id,l.name,l.description,
      RTRIM(l.id||'.0.WEATHER'),
      (SELECT id from device_types where name ='FCT/Weather'),'0'
  FROM input i JOIN 
  locations l ON l.guid = i._site_guid
  RETURNING devices.*
  )
  SELECT id 
  INTO _id 
  FROM dev_ins
  ;
  EXECUTE 'INSERT INTO' ||_schema_nm||'.telemetries(diagnostic_type_id, device_id, value, ts)
  SELECT (SELECT id from diagnostic_types where name =dg_type),'||_id||',input.ts,input.val
  FROM input,dev_ins
  ON CONFLICT (diagnostic_type_id, ts, device_id) DO NOTHING';
  END
  ;
  $function$
  ;
  </code></pre>
  <p>When i execute the function like this in python:</p>
  <pre><code>cur.execute(&quot;SELECT weather_crup( %s )&quot;, (json_object,) )
  </code></pre>
  <p>I get the error:</p>
  <blockquote>
  <p>NullValueNotAllowed: query string argument of EXECUTE is null
  CONTEXT:  PL/pgSQL function weather_crup(jsonb) line 35 at EXECUTE</p>
  </blockquote>