@@ -7988,18 +7988,8 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
79887988 i_oid,
79897989 i_tgrelid,
79907990 i_tgname,
7991- i_tgfname,
7992- i_tgtype,
7993- i_tgnargs,
7994- i_tgargs,
7995- i_tgisconstraint,
7996- i_tgconstrname,
7997- i_tgconstrrelid,
7998- i_tgconstrrelname,
79997991 i_tgenabled,
80007992 i_tgispartition,
8001- i_tgdeferrable,
8002- i_tginitdeferred,
80037993 i_tgdef;
80047994
80057995 /*
@@ -8038,7 +8028,6 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
80388028 */
80398029 appendPQExpBuffer(query,
80408030 "SELECT t.tgrelid, t.tgname, "
8041- "t.tgfoid::pg_catalog.regproc AS tgfname, "
80428031 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
80438032 "t.tgenabled, t.tableoid, t.oid, "
80448033 "t.tgparentid <> 0 AS tgispartition\n"
@@ -8062,7 +8051,6 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
80628051 */
80638052 appendPQExpBuffer(query,
80648053 "SELECT t.tgrelid, t.tgname, "
8065- "t.tgfoid::pg_catalog.regproc AS tgfname, "
80668054 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
80678055 "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition\n"
80688056 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
@@ -8083,7 +8071,6 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
80838071 */
80848072 appendPQExpBuffer(query,
80858073 "SELECT t.tgrelid, t.tgname, "
8086- "t.tgfoid::pg_catalog.regproc AS tgfname, "
80878074 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
80888075 "t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition "
80898076 "FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
@@ -8102,7 +8089,6 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
81028089 /* See above about pretty=true in pg_get_triggerdef */
81038090 appendPQExpBuffer(query,
81048091 "SELECT t.tgrelid, t.tgname, "
8105- "t.tgfoid::pg_catalog.regproc AS tgfname, "
81068092 "pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
81078093 "t.tgenabled, false as tgispartition, "
81088094 "t.tableoid, t.oid "
@@ -8121,18 +8107,8 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
81218107 i_oid = PQfnumber(res, "oid");
81228108 i_tgrelid = PQfnumber(res, "tgrelid");
81238109 i_tgname = PQfnumber(res, "tgname");
8124- i_tgfname = PQfnumber(res, "tgfname");
8125- i_tgtype = PQfnumber(res, "tgtype");
8126- i_tgnargs = PQfnumber(res, "tgnargs");
8127- i_tgargs = PQfnumber(res, "tgargs");
8128- i_tgisconstraint = PQfnumber(res, "tgisconstraint");
8129- i_tgconstrname = PQfnumber(res, "tgconstrname");
8130- i_tgconstrrelid = PQfnumber(res, "tgconstrrelid");
8131- i_tgconstrrelname = PQfnumber(res, "tgconstrrelname");
81328110 i_tgenabled = PQfnumber(res, "tgenabled");
81338111 i_tgispartition = PQfnumber(res, "tgispartition");
8134- i_tgdeferrable = PQfnumber(res, "tgdeferrable");
8135- i_tginitdeferred = PQfnumber(res, "tginitdeferred");
81368112 i_tgdef = PQfnumber(res, "tgdef");
81378113
81388114 tginfo = (TriggerInfo *) pg_malloc(ntups * sizeof(TriggerInfo));
@@ -8181,57 +8157,7 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
81818157 tginfo[j].tgtable = tbinfo;
81828158 tginfo[j].tgenabled = *(PQgetvalue(res, j, i_tgenabled));
81838159 tginfo[j].tgispartition = *(PQgetvalue(res, j, i_tgispartition)) == 't';
8184- if (i_tgdef >= 0)
8185- {
8186- tginfo[j].tgdef = pg_strdup(PQgetvalue(res, j, i_tgdef));
8187-
8188- /* remaining fields are not valid if we have tgdef */
8189- tginfo[j].tgfname = NULL;
8190- tginfo[j].tgtype = 0;
8191- tginfo[j].tgnargs = 0;
8192- tginfo[j].tgargs = NULL;
8193- tginfo[j].tgisconstraint = false;
8194- tginfo[j].tgdeferrable = false;
8195- tginfo[j].tginitdeferred = false;
8196- tginfo[j].tgconstrname = NULL;
8197- tginfo[j].tgconstrrelid = InvalidOid;
8198- tginfo[j].tgconstrrelname = NULL;
8199- }
8200- else
8201- {
8202- tginfo[j].tgdef = NULL;
8203-
8204- tginfo[j].tgfname = pg_strdup(PQgetvalue(res, j, i_tgfname));
8205- tginfo[j].tgtype = atoi(PQgetvalue(res, j, i_tgtype));
8206- tginfo[j].tgnargs = atoi(PQgetvalue(res, j, i_tgnargs));
8207- tginfo[j].tgargs = pg_strdup(PQgetvalue(res, j, i_tgargs));
8208- tginfo[j].tgisconstraint = *(PQgetvalue(res, j, i_tgisconstraint)) == 't';
8209- tginfo[j].tgdeferrable = *(PQgetvalue(res, j, i_tgdeferrable)) == 't';
8210- tginfo[j].tginitdeferred = *(PQgetvalue(res, j, i_tginitdeferred)) == 't';
8211-
8212- if (tginfo[j].tgisconstraint)
8213- {
8214- tginfo[j].tgconstrname = pg_strdup(PQgetvalue(res, j, i_tgconstrname));
8215- tginfo[j].tgconstrrelid = atooid(PQgetvalue(res, j, i_tgconstrrelid));
8216- if (OidIsValid(tginfo[j].tgconstrrelid))
8217- {
8218- if (PQgetisnull(res, j, i_tgconstrrelname))
8219- pg_fatal("query produced null referenced table name for foreign key trigger \"%s\" on table \"%s\" (OID of table: %u)",
8220- tginfo[j].dobj.name,
8221- tbinfo->dobj.name,
8222- tginfo[j].tgconstrrelid);
8223- tginfo[j].tgconstrrelname = pg_strdup(PQgetvalue(res, j, i_tgconstrrelname));
8224- }
8225- else
8226- tginfo[j].tgconstrrelname = NULL;
8227- }
8228- else
8229- {
8230- tginfo[j].tgconstrname = NULL;
8231- tginfo[j].tgconstrrelid = InvalidOid;
8232- tginfo[j].tgconstrrelname = NULL;
8233- }
8234- }
8160+ tginfo[j].tgdef = pg_strdup(PQgetvalue(res, j, i_tgdef));
82358161 }
82368162 }
82378163
@@ -17776,10 +17702,6 @@ dumpTrigger(Archive *fout, const TriggerInfo *tginfo)
1777617702 PQExpBuffer trigprefix;
1777717703 PQExpBuffer trigidentity;
1777817704 char *qtabname;
17779- char *tgargs;
17780- size_t lentgargs;
17781- const char *p;
17782- int findx;
1778317705 char *tag;
1778417706
1778517707 /* Do nothing in data-only dump */
@@ -17796,121 +17718,9 @@ dumpTrigger(Archive *fout, const TriggerInfo *tginfo)
1779617718 appendPQExpBuffer(trigidentity, "%s ", fmtId(tginfo->dobj.name));
1779717719 appendPQExpBuffer(trigidentity, "ON %s", fmtQualifiedDumpable(tbinfo));
1779817720
17721+ appendPQExpBuffer(query, "%s;\n", tginfo->tgdef);
1779917722 appendPQExpBuffer(delqry, "DROP TRIGGER %s;\n", trigidentity->data);
1780017723
17801- if (tginfo->tgdef)
17802- {
17803- appendPQExpBuffer(query, "%s;\n", tginfo->tgdef);
17804- }
17805- else
17806- {
17807- if (tginfo->tgisconstraint)
17808- {
17809- appendPQExpBufferStr(query, "CREATE CONSTRAINT TRIGGER ");
17810- appendPQExpBufferStr(query, fmtId(tginfo->tgconstrname));
17811- }
17812- else
17813- {
17814- appendPQExpBufferStr(query, "CREATE TRIGGER ");
17815- appendPQExpBufferStr(query, fmtId(tginfo->dobj.name));
17816- }
17817- appendPQExpBufferStr(query, "\n ");
17818-
17819- /* Trigger type */
17820- if (TRIGGER_FOR_BEFORE(tginfo->tgtype))
17821- appendPQExpBufferStr(query, "BEFORE");
17822- else if (TRIGGER_FOR_AFTER(tginfo->tgtype))
17823- appendPQExpBufferStr(query, "AFTER");
17824- else if (TRIGGER_FOR_INSTEAD(tginfo->tgtype))
17825- appendPQExpBufferStr(query, "INSTEAD OF");
17826- else
17827- pg_fatal("unexpected tgtype value: %d", tginfo->tgtype);
17828-
17829- findx = 0;
17830- if (TRIGGER_FOR_INSERT(tginfo->tgtype))
17831- {
17832- appendPQExpBufferStr(query, " INSERT");
17833- findx++;
17834- }
17835- if (TRIGGER_FOR_DELETE(tginfo->tgtype))
17836- {
17837- if (findx > 0)
17838- appendPQExpBufferStr(query, " OR DELETE");
17839- else
17840- appendPQExpBufferStr(query, " DELETE");
17841- findx++;
17842- }
17843- if (TRIGGER_FOR_UPDATE(tginfo->tgtype))
17844- {
17845- if (findx > 0)
17846- appendPQExpBufferStr(query, " OR UPDATE");
17847- else
17848- appendPQExpBufferStr(query, " UPDATE");
17849- findx++;
17850- }
17851- if (TRIGGER_FOR_TRUNCATE(tginfo->tgtype))
17852- {
17853- if (findx > 0)
17854- appendPQExpBufferStr(query, " OR TRUNCATE");
17855- else
17856- appendPQExpBufferStr(query, " TRUNCATE");
17857- findx++;
17858- }
17859- appendPQExpBuffer(query, " ON %s\n",
17860- fmtQualifiedDumpable(tbinfo));
17861-
17862- if (tginfo->tgisconstraint)
17863- {
17864- if (OidIsValid(tginfo->tgconstrrelid))
17865- {
17866- /* regclass output is already quoted */
17867- appendPQExpBuffer(query, " FROM %s\n ",
17868- tginfo->tgconstrrelname);
17869- }
17870- if (!tginfo->tgdeferrable)
17871- appendPQExpBufferStr(query, "NOT ");
17872- appendPQExpBufferStr(query, "DEFERRABLE INITIALLY ");
17873- if (tginfo->tginitdeferred)
17874- appendPQExpBufferStr(query, "DEFERRED\n");
17875- else
17876- appendPQExpBufferStr(query, "IMMEDIATE\n");
17877- }
17878-
17879- if (TRIGGER_FOR_ROW(tginfo->tgtype))
17880- appendPQExpBufferStr(query, " FOR EACH ROW\n ");
17881- else
17882- appendPQExpBufferStr(query, " FOR EACH STATEMENT\n ");
17883-
17884- /* regproc output is already sufficiently quoted */
17885- appendPQExpBuffer(query, "EXECUTE FUNCTION %s(",
17886- tginfo->tgfname);
17887-
17888- tgargs = (char *) PQunescapeBytea((unsigned char *) tginfo->tgargs,
17889- &lentgargs);
17890- p = tgargs;
17891- for (findx = 0; findx < tginfo->tgnargs; findx++)
17892- {
17893- /* find the embedded null that terminates this trigger argument */
17894- size_t tlen = strlen(p);
17895-
17896- if (p + tlen >= tgargs + lentgargs)
17897- {
17898- /* hm, not found before end of bytea value... */
17899- pg_fatal("invalid argument string (%s) for trigger \"%s\" on table \"%s\"",
17900- tginfo->tgargs,
17901- tginfo->dobj.name,
17902- tbinfo->dobj.name);
17903- }
17904-
17905- if (findx > 0)
17906- appendPQExpBufferStr(query, ", ");
17907- appendStringLiteralAH(query, p, fout);
17908- p += tlen + 1;
17909- }
17910- free(tgargs);
17911- appendPQExpBufferStr(query, ");\n");
17912- }
17913-
1791417724 /* Triggers can depend on extensions */
1791517725 append_depends_on_extension(fout, query, &tginfo->dobj,
1791617726 "pg_catalog.pg_trigger", "TRIGGER",
0 commit comments