gp function cannot execute on segment because it issues a non-SELECT statement
<p>i got errors when i created the partition tables automatically via trigger which is created in advance.</p>

<p><strong>enviorment info:</strong></p>

<p>GP version :4.3.8.1</p>

<p><strong>error:</strong></p>

<pre><code>NOTICE:  Found 2 data formatting errors (2 or more input rows). Rejected related input data.
ERROR:  function cannot execute on segment because it issues a non-SELECT statement (functions.c:135)  (seg13 ZHJK-HADOOP-SLAVE6:40001 pid=19959) (cdbdisp.c:1326)
DETAIL:  
SQL statement "CREATE TABLE T_FM_HISTORYALARM_20160101(CONSTRAINT T_FM_HISTORYALARM_20160101_eventtime_check CHECK (EVENTTIME &gt;= timestamp '20160101000000' AND EVENTTIME &lt; (timestamp '20160101000000' + interval '1 day')))INHERITS (T_FM_HISTORYALARM)"
PL/pgSQL function "history_alarm_partition" line 36 at execute statement
********** 错误 **********

ERROR: function cannot execute on segment because it issues a non-SELECT statement (functions.c:135)  (seg13 ZHJK-HADOOP-SLAVE6:40001 pid=19959) (cdbdisp.c:1326)
SQL 状态: XX000
详细:
SQL statement "CREATE TABLE T_FM_HISTORYALARM_20160101(CONSTRAINT T_FM_HISTORYALARM_20160101_eventtime_check CHECK (EVENTTIME &gt;= timestamp '20160101000000' AND EVENTTIME &lt; (timestamp '20160101000000' + interval '1 day')))INHERITS (T_FM_HISTORYALARM)"
PL/pgSQL function "history_alarm_partition" line 36 at execute statement
</code></pre>

<p><strong>function code:</strong></p>

<pre><code>    CREATE OR REPLACE FUNCTION history_alarm_partition()  
  RETURNS trigger AS  
$BODY$  
DECLARE tbl_name CHARACTER VARYING;  
    tbl_name_parent CHARACTER VARYING := 'T_FM_HISTORYALARM';
    tbl_name_salve CHARACTER VARYING;  
    tbl_year INTEGER;  
    tbl_month INTEGER;  
    tbl_day INTEGER;
    create_tbl_sql CHARACTER VARYING;  
    insert_tbl_sql CHARACTER VARYING;  
    index_sql CHARACTER VARYING;  
BEGIN   
    SELECT date_part('year',NEW.EVENTTIME)  INTO tbl_year;  
    SELECT date_part('month',NEW.EVENTTIME) INTO tbl_month;  
    SELECT date_part('day',NEW.EVENTTIME) INTO tbl_day;
    IF(tbl_month&lt;10)THEN  
        tbl_name_salve=tbl_year||'0'||tbl_month;  
    ELSE   
        tbl_name_salve=tbl_year||tbl_month;  
    END IF;
    IF(tbl_day&lt;10)THEN
        tbl_name_salve=tbl_name_salve||'0'||tbl_day;
    ELSE
        tbl_name_salve=tbl_name_salve||tbl_day;
    END IF;  
    tbl_name=tbl_name_parent||'_'||tbl_name_salve;  

    --判断表 时间分段表是否存在  
    IF ( (SELECT count(relname) FROM pg_class WHERE relname=tbl_name)&gt;0) THEN  
        insert_tbl_sql='INSERT INTO '||tbl_name ||' VALUES(NEW.*)';  
        EXECUTE insert_tbl_sql;  
    ELSE   
        create_tbl_sql='CREATE TABLE '||tbl_name  
        ||'('  
        ||  'CONSTRAINT '||tbl_name||'_EVENTTIME_CHECK'||' CHECK (EVENTTIME &gt;= timestamp '''||tbl_name_salve||'000000''' ||' AND EVENTTIME &lt; (timestamp '''||tbl_name_salve||'000000'' + interval ''1 day''))'  
        ||')INHERITS ('||tbl_name_parent||')';  
        EXECUTE create_tbl_sql;  

        index_sql='CREATE INDEX '||tbl_name||'_EVENTTIME_INDEX ON '||tbl_name||'EVENTTIME';  
        EXECUTE index_sql;  

        insert_tbl_sql='INSERT INTO '||tbl_name ||' VALUES(NEW.*)';  
        EXECUTE insert_tbl_sql;  
    END IF;  
    RETURN NULL;  
END;  
$BODY$  
  LANGUAGE plpgsql VOLATILE 
</code></pre>

<p><strong>create trigger code:</strong></p>

<pre><code>create trigger history_alarm_trigger before insert or update on t_fm_historyalarm for each row execute procedure history_alarm_partition();
</code></pre>

<p>it is ok when the funtion and trigger are executed , but when the values are inserted into the table T_FM_HISTORYALARM , the parent table ,the error occures.</p>

<p>if i execute the create table statmenet :</p>

<pre><code>CREATE TABLE T_FM_HISTORYALARM_20160101(CONSTRAINT T_FM_HISTORYALARM_20160101_eventtime_check CHECK (EVENTTIME &gt;= timestamp '20160101000000' AND EVENTTIME &lt; (timestamp '20160101000000' + interval '1 day')))INHERITS (T_FM_HISTORYALARM)
</code></pre>

<p>it works well.</p>

<p>can you give me some advice?
thank you very much.</p>