title: ERROR: cannot cast type integer to json in Postgresql
body: <p>When I am trying to insert the record in <code>tableA</code>, i am getting the below error:</p>
  
  <pre><code>QUERY:  insert into schemaname.tableB(col1, col2) values(....)
  CONTEXT:  PL/pgSQL function schemaname.funcA() line 5 at SQL statement
  ********** Error **********
  ERROR: cannot cast type integer to json
  SQL state: 42846
  Context: PL/pgSQL function schemaname.funcA() line 5 at SQL statement
  </code></pre>
  
  <p>I have created following trigger which function when record gets committed:</p>
  
  <pre><code>CREATE CONSTRAINT TRIGGER trg_name
    AFTER INSERT
    ON schemaname.tableA
    DEFERRABLE INITIALLY DEFERRED
    FOR EACH ROW
    EXECUTE PROCEDURE schemaname.funcA();
  </code></pre>
  
  <p>In the below trigger function <code>col1</code> is of integer type and <code>col2</code> is of json type.</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION schemaname.funcA()
    RETURNS trigger AS
  $BODY$
  
  BEGIN
  
  insert into schemaname.tableB(col1, col2) values(NEW.val1, json_build_object("abc", NEW.col2val1::json, "def", NEW.col2val2::json, "ghi", NEW.col2val3::json));
  
  RETURN NEW;
  
  END;
  $BODY$
    LANGUAGE plpgsql VOLATILE
    COST 100;
  </code></pre>
  
  <p>Could you please help me what could be the cause of this error?</p>