diff --git a/src/common/backend/utils/adt/ruleutils.cpp b/src/common/backend/utils/adt/ruleutils.cpp index 241a6c6ff..c36411461 100644 --- a/src/common/backend/utils/adt/ruleutils.cpp +++ b/src/common/backend/utils/adt/ruleutils.cpp @@ -3193,9 +3193,11 @@ static char* pg_get_triggerdef_worker(Oid trigid, bool pretty) } if (tgfbody != NULL) { - char* tgordername = DatumGetCString(fastgetattr(ht_trig, Anum_pg_trigger_tgordername, tgrel->rd_att, &isnull)); - char* tgorder = DatumGetCString(fastgetattr(ht_trig, Anum_pg_trigger_tgorder, tgrel->rd_att, &isnull)); - if (tgorder != NULL) + bool isordernull = false; + bool isordernamenull = false; + char* tgordername = DatumGetCString(fastgetattr(ht_trig, Anum_pg_trigger_tgordername, tgrel->rd_att, &isordernamenull)); + char* tgorder = DatumGetCString(fastgetattr(ht_trig, Anum_pg_trigger_tgorder, tgrel->rd_att, &isordernull)); + if (!isordernull && !isordernamenull) appendStringInfo(&buf, "%s %s ", tgorder, tgordername); appendStringInfo(&buf, "%s;", tgfbody); diff --git a/src/gausskernel/optimizer/commands/trigger.cpp b/src/gausskernel/optimizer/commands/trigger.cpp index dff2df9c5..0503f1e87 100644 --- a/src/gausskernel/optimizer/commands/trigger.cpp +++ b/src/gausskernel/optimizer/commands/trigger.cpp @@ -730,13 +730,13 @@ ObjectAddress CreateTrigger(CreateTrigStmt* stmt, const char* queryString, Oid r } } } else { - values[Anum_pg_trigger_tgordername - 1] = DirectFunctionCall1(namein, CStringGetDatum("")); - values[Anum_pg_trigger_tgorder - 1] = DirectFunctionCall1(namein, CStringGetDatum("")); + nulls[Anum_pg_trigger_tgordername - 1] = true; + nulls[Anum_pg_trigger_tgorder - 1] = true; } } else { - values[Anum_pg_trigger_tgordername - 1] = DirectFunctionCall1(namein, CStringGetDatum("")); - values[Anum_pg_trigger_tgorder - 1] = DirectFunctionCall1(namein, CStringGetDatum("")); - values[Anum_pg_trigger_tgtime - 1] = DirectFunctionCall1(namein, CStringGetDatum("")); + nulls[Anum_pg_trigger_tgordername - 1] = true; + nulls[Anum_pg_trigger_tgorder - 1] = true; + nulls[Anum_pg_trigger_tgtime - 1] = true; } if (stmt->args) { ListCell* le = NULL; @@ -1699,13 +1699,12 @@ void RelationBuildTriggers(Relation relation) char* trigname = DatumGetCString(DirectFunctionCall1(nameout, NameGetDatum(&pg_trigger->tgname))); char* tgordername = DatumGetCString(fastgetattr(htup, Anum_pg_trigger_tgordername, tgrel->rd_att, &isnull)); char* tgorder = DatumGetCString(fastgetattr(htup, Anum_pg_trigger_tgorder, tgrel->rd_att, &isnull)); - char* tgtime = DatumGetCString(fastgetattr(htup, Anum_pg_trigger_tgtime, tgrel->rd_att, &isnull)); - if (strcmp(tgorder, "follows") == 0) { + if (!isnull && strcmp(tgorder, "follows") == 0) { tgNameInfo->follows_name = tgordername; tgNameInfo->precedes_name = NULL; is_has_follows = true; } - else if (strcmp(tgorder, "precedes") == 0) { + else if (!isnull && strcmp(tgorder, "precedes") == 0) { tgNameInfo->follows_name = NULL; tgNameInfo->precedes_name = tgordername; is_has_follows = true; @@ -1714,8 +1713,9 @@ void RelationBuildTriggers(Relation relation) tgNameInfo->follows_name = NULL; tgNameInfo->precedes_name = NULL; } + char* tgtime = DatumGetCString(fastgetattr(htup, Anum_pg_trigger_tgtime, tgrel->rd_att, &isnull)); tgNameInfo->trg_name = trigname; - tgNameInfo->time = tgtime; + tgNameInfo->time = isnull ? NULL:tgtime; } build = &(triggers[numtrigs]); build->tgoid = HeapTupleGetOid(htup); @@ -1787,7 +1787,7 @@ void RelationBuildTriggers(Relation relation) TriggerNameInfo temp = tgNameInfos[end+gap]; Trigger tgtmp = triggers[end+gap]; while (end >= 0) { - if (strcmp(tmp, tgNameInfos[end].time)<0) { + if (tmp != NULL && tgNameInfos[end].time != NULL && strcmp(tmp, tgNameInfos[end].time)<0) { tgNameInfos[end+gap] = tgNameInfos[end]; triggers[end+gap] = triggers[end]; end -= gap;