@@ -7988,18 +7988,8 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
7988
7988
i_oid,
7989
7989
i_tgrelid,
7990
7990
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,
7999
7991
i_tgenabled,
8000
7992
i_tgispartition,
8001
- i_tgdeferrable,
8002
- i_tginitdeferred,
8003
7993
i_tgdef;
8004
7994
8005
7995
/*
@@ -8038,7 +8028,6 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
8038
8028
*/
8039
8029
appendPQExpBuffer(query,
8040
8030
"SELECT t.tgrelid, t.tgname, "
8041
- "t.tgfoid::pg_catalog.regproc AS tgfname, "
8042
8031
"pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8043
8032
"t.tgenabled, t.tableoid, t.oid, "
8044
8033
"t.tgparentid <> 0 AS tgispartition\n"
@@ -8062,7 +8051,6 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
8062
8051
*/
8063
8052
appendPQExpBuffer(query,
8064
8053
"SELECT t.tgrelid, t.tgname, "
8065
- "t.tgfoid::pg_catalog.regproc AS tgfname, "
8066
8054
"pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8067
8055
"t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition\n"
8068
8056
"FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
@@ -8083,7 +8071,6 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
8083
8071
*/
8084
8072
appendPQExpBuffer(query,
8085
8073
"SELECT t.tgrelid, t.tgname, "
8086
- "t.tgfoid::pg_catalog.regproc AS tgfname, "
8087
8074
"pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8088
8075
"t.tgenabled, t.tableoid, t.oid, t.tgisinternal as tgispartition "
8089
8076
"FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
@@ -8102,7 +8089,6 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
8102
8089
/* See above about pretty=true in pg_get_triggerdef */
8103
8090
appendPQExpBuffer(query,
8104
8091
"SELECT t.tgrelid, t.tgname, "
8105
- "t.tgfoid::pg_catalog.regproc AS tgfname, "
8106
8092
"pg_catalog.pg_get_triggerdef(t.oid, false) AS tgdef, "
8107
8093
"t.tgenabled, false as tgispartition, "
8108
8094
"t.tableoid, t.oid "
@@ -8121,18 +8107,8 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
8121
8107
i_oid = PQfnumber(res, "oid");
8122
8108
i_tgrelid = PQfnumber(res, "tgrelid");
8123
8109
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");
8132
8110
i_tgenabled = PQfnumber(res, "tgenabled");
8133
8111
i_tgispartition = PQfnumber(res, "tgispartition");
8134
- i_tgdeferrable = PQfnumber(res, "tgdeferrable");
8135
- i_tginitdeferred = PQfnumber(res, "tginitdeferred");
8136
8112
i_tgdef = PQfnumber(res, "tgdef");
8137
8113
8138
8114
tginfo = (TriggerInfo *) pg_malloc(ntups * sizeof(TriggerInfo));
@@ -8181,57 +8157,7 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
8181
8157
tginfo[j].tgtable = tbinfo;
8182
8158
tginfo[j].tgenabled = *(PQgetvalue(res, j, i_tgenabled));
8183
8159
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));
8235
8161
}
8236
8162
}
8237
8163
@@ -17776,10 +17702,6 @@ dumpTrigger(Archive *fout, const TriggerInfo *tginfo)
17776
17702
PQExpBuffer trigprefix;
17777
17703
PQExpBuffer trigidentity;
17778
17704
char *qtabname;
17779
- char *tgargs;
17780
- size_t lentgargs;
17781
- const char *p;
17782
- int findx;
17783
17705
char *tag;
17784
17706
17785
17707
/* Do nothing in data-only dump */
@@ -17796,121 +17718,9 @@ dumpTrigger(Archive *fout, const TriggerInfo *tginfo)
17796
17718
appendPQExpBuffer(trigidentity, "%s ", fmtId(tginfo->dobj.name));
17797
17719
appendPQExpBuffer(trigidentity, "ON %s", fmtQualifiedDumpable(tbinfo));
17798
17720
17721
+ appendPQExpBuffer(query, "%s;\n", tginfo->tgdef);
17799
17722
appendPQExpBuffer(delqry, "DROP TRIGGER %s;\n", trigidentity->data);
17800
17723
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
-
17914
17724
/* Triggers can depend on extensions */
17915
17725
append_depends_on_extension(fout, query, &tginfo->dobj,
17916
17726
"pg_catalog.pg_trigger", "TRIGGER",
0 commit comments