title: Error code 23514 in postgresql when insert into partitioned table
body: <p>I have a table in postgresql with the structure such as:</p>
  
  <pre><code>CREATE TABLE public.user_event_firebase
  (
      user_id character varying(32) NOT NULL,
      event_name character varying(255) NOT NULL,
      timestamp bigint NOT NULL,
      platform character varying(255) NOT NULL,
      created_at timestamp without time zone DEFAULT now()
  )
  </code></pre>
  
  <p>and I created some partition table via month such as <code>tableA_YYYY_MM</code>  with YYYY is year, MM is month by procedure such as: </p>
  
  <pre><code>CREATE OR REPLACE FUNCTION public.create_partition_table_function(date, date)
   RETURNS void
   LANGUAGE plpgsql
  AS $function$
  DECLARE
      create_query text;
      index_query text;
  BEGIN
      FOR create_query, index_query IN SELECT
              'create table if not exists user_event_firebase_'
              || TO_CHAR( d, 'YYYY_MM' )
              || '() inherits ( user_event_firebase );',
              'create index if not exists user_event_firebase_'
              || TO_CHAR( d, 'YYYY_MM' )
              || '_time on user_event_firebase_'
              || TO_CHAR( d, 'YYYY_MM' )
              || ' ( timestamp,event_name,platform,user_id );'
          FROM generate_series( $1, $2, '1 month' ) AS d
      LOOP
          EXECUTE create_query;
          EXECUTE index_query;
      END LOOP;
  END;
  $function$
  </code></pre>
  
  <p>I've been created insert into these partitioned table with insert_by_partition_function_3 function</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION public.insert_by_partition_function_3()
   RETURNS trigger
   LANGUAGE plpgsql
  AS $function$
  BEGIN        
      EXECUTE 'insert into user_event_firebase_'
              || to_char(to_timestamp(NEW.timestamp / 1000), 'YYYY_MM' )
              || ' values ( $1, $2, $3, $4 )' USING NEW.user_id, NEW.event_name, NEW.timestamp, NEW.platform;
          RETURN NULL;
  
  END;
  $function$
  </code></pre>
  
  <p>Apply trigger </p>
  
  <pre><code>CREATE TRIGGER partition_trigger_function_1
      BEFORE INSERT
      ON user_event_firebase
      FOR each ROW
      EXECUTE PROCEDURE insert_by_partition_function_3() ;
  </code></pre>
  
  <p>But when I insert into these partitioned table. It throw an error about  <strong>23514 : check_violation [Integrity Constraint Violation]</strong></p>
  
  <blockquote>
    <p>{"name":"error","length":539,"severity":"ERROR","code":"23514","detail":"Failing
    row contains (5abd344fa9dd172024b8b661, reg_wal_continue_v6,
    1522530933094, ios, 2018-09-06 17:26:54.98615).","where":"SQL
    statement \"insert into user_event_firebase_2018_04 values ( $1, $2,
    $3, $4 )\"\nPL/pgSQL function insert_by_partition_function_3() line 3
    at
    EXECUTE","schema":"public","table":"user_event_firebase_2018_04","constraint":"user_event_firebase_2018_04_created_at_check","file":"execMain.c","line":"1760","routine":"ExecConstraints"}</p>
  </blockquote>
  
  <p>When I get constraint from table, I have information such as</p>
  
  <pre><code>"user_event_firebase_2018_04_created_at_check","2200","c",f,f,t,"60055","0","0","0"," "," "," ",t,0,f,"{5}",null,null,null,null,null,"{BOOLEXPR :boolop and :args ({OPEXPR :opno 2374 :opfuncid 2368 :opresulttype 16 :opretset false :opcollid 0 :inputcollid 0 :args ({VAR :varno 1 :varattno 5 :vartype 1114 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 5 :location 64} {CONST :consttype 1082 :consttypmod -1 :constcollid 0 :constlen 4 :constbyval true :constisnull false :location 83 :constvalue 4 [ 9 26 0 0 0 0 0 0 ]}) :location 75} {OPEXPR :opno 2371 :opfuncid 2364 :opresulttype 16 :opretset false :opcollid 0 :inputcollid 0 :args ({VAR :varno 1 :varattno 5 :vartype 1114 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 5 :location 100} {CONST :consttype 1082 :consttypmod -1 :constcollid 0 :constlen 4 :constbyval true :constisnull false :location 118 :constvalue 4 [ 39 26 0 0 0 0 0 0 ]}) :location 111}) :location 96}","((created_at &gt;= '2018-04-01'::date) AND (created_at &lt; '2018-05-01'::date))"
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/idfqf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/idfqf.png" alt="enter image description here"></a></p>
  
  <p>Is there any solution to solve this problem?</p>
  
  <p>Regards.</p>