title: Escape quotes on psql to avoid SQLInjections
body: <p>I'm doing a function to compare JSONs and then insert on a table (trigger) only the differences.
  The function works perfectly when none of the registers come with a quote. So I would to know how to escape these quotes that may come:</p>
  <pre class="lang-sql prettyprint-override"><code>CREATE OR REPLACE FUNCTION public.fnc_compare_jsonb(old_reg jsonb, new_reg jsonb)
   RETURNS jsonb
   LANGUAGE plpgsql
   IMMUTABLE STRICT
  AS $function$
  declare
      keys record;
      jsonb_return jsonb = '{}'::jsonb;
  begin
      for keys in
          select *
          from jsonb_object_keys($1)
      loop
          if $1 -&gt; keys.jsonb_object_keys &lt;&gt; $2 -&gt; keys.jsonb_object_keys then
              jsonb_return = jsonb_return || format('{&quot;%s&quot;: &quot;%s&quot;}', keys.jsonb_object_keys, $2 -&gt;&gt; keys.jsonb_object_keys)::jsonb;
          end if;
      end loop;
      return jsonb_return;
  end
  $function$
  ;
  </code></pre>
  <p>The error is happening on line:</p>
  <pre><code>jsonb_return = jsonb_return || format('{&quot;%s&quot;: &quot;%s&quot;}', keys.jsonb_object_keys, $2 -&gt;&gt; keys.jsonb_object_keys)::jsonb;
  </code></pre>
  <pre><code>SQL Error [22P02]: ERROR: invalid input syntax for type json
    Detail: Token &quot;@&quot; is invalid.
    Where: JSON data, line 1: {&quot;email&quot;: &quot;test2&quot;@...
  PL/pgSQL function ecidadao.fnc_compare_jsonb(jsonb,jsonb) line 11 at assignment
  </code></pre>