-
Notifications
You must be signed in to change notification settings - Fork 1
/
Add-FOREIGN-to-ALTER-statements-pg13.patch
178 lines (164 loc) · 6.76 KB
/
Add-FOREIGN-to-ALTER-statements-pg13.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index f01fea5b91..65abc22e7a 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -15550,6 +15550,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
{
char *ftoptions = NULL;
char *srvname = NULL;
+ char *foreign = "";
switch (tbinfo->relkind)
{
@@ -15583,6 +15584,8 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
ftoptions = pg_strdup(PQgetvalue(res, 0, i_ftoptions));
PQclear(res);
destroyPQExpBuffer(query);
+
+ foreign = "FOREIGN ";
break;
}
case RELKIND_MATVIEW:
@@ -15924,7 +15927,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
continue;
appendPQExpBufferStr(q, "\n-- For binary upgrade, set up inherited constraint.\n");
- appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
+ appendPQExpBuffer(q, "ALTER %sTABLE ONLY %s ", foreign,
qualrelname);
appendPQExpBuffer(q, " ADD CONSTRAINT %s ",
fmtId(constr->dobj.name));
@@ -15945,7 +15948,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
{
TableInfo *parentRel = parents[k];
- appendPQExpBuffer(q, "ALTER TABLE ONLY %s INHERIT %s;\n",
+ appendPQExpBuffer(q, "ALTER %sTABLE ONLY %s INHERIT %s;\n", foreign,
qualrelname,
fmtQualifiedDumpable(parentRel));
}
@@ -16051,7 +16054,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
if (!shouldPrintColumn(dopt, tbinfo, j) &&
tbinfo->notnull[j] && !tbinfo->inhNotNull[j])
{
- appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
+ appendPQExpBuffer(q, "ALTER %sTABLE ONLY %s ", foreign,
qualrelname);
appendPQExpBuffer(q, "ALTER COLUMN %s SET NOT NULL;\n",
fmtId(tbinfo->attnames[j]));
@@ -16064,7 +16067,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
*/
if (tbinfo->attstattarget[j] >= 0)
{
- appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
+ appendPQExpBuffer(q, "ALTER %sTABLE ONLY %s ", foreign,
qualrelname);
appendPQExpBuffer(q, "ALTER COLUMN %s ",
fmtId(tbinfo->attnames[j]));
@@ -16101,7 +16104,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
*/
if (storage != NULL)
{
- appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
+ appendPQExpBuffer(q, "ALTER %sTABLE ONLY %s ", foreign,
qualrelname);
appendPQExpBuffer(q, "ALTER COLUMN %s ",
fmtId(tbinfo->attnames[j]));
@@ -16115,7 +16118,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
*/
if (tbinfo->attoptions[j][0] != '\0')
{
- appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
+ appendPQExpBuffer(q, "ALTER %sTABLE ONLY %s ", foreign,
qualrelname);
appendPQExpBuffer(q, "ALTER COLUMN %s ",
fmtId(tbinfo->attnames[j]));
@@ -16238,6 +16241,7 @@ dumpAttrDef(Archive *fout, AttrDefInfo *adinfo)
PQExpBuffer delq;
char *qualrelname;
char *tag;
+ char *foreign;
/* Skip if table definition not to be dumped */
if (!tbinfo->dobj.dump || dopt->dataOnly)
@@ -16252,13 +16256,15 @@ dumpAttrDef(Archive *fout, AttrDefInfo *adinfo)
qualrelname = pg_strdup(fmtQualifiedDumpable(tbinfo));
- appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
+ foreign = tbinfo->relkind == RELKIND_FOREIGN_TABLE ? "FOREIGN " : "";
+
+ appendPQExpBuffer(q, "ALTER %sTABLE ONLY %s ", foreign,
qualrelname);
appendPQExpBuffer(q, "ALTER COLUMN %s SET DEFAULT %s;\n",
fmtId(tbinfo->attnames[adnum - 1]),
adinfo->adef_expr);
- appendPQExpBuffer(delq, "ALTER TABLE %s ",
+ appendPQExpBuffer(delq, "ALTER %sTABLE %s ", foreign,
qualrelname);
appendPQExpBuffer(delq, "ALTER COLUMN %s DROP DEFAULT;\n",
fmtId(tbinfo->attnames[adnum - 1]));
@@ -16564,6 +16570,7 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
PQExpBuffer q;
PQExpBuffer delq;
char *tag = NULL;
+ char *foreign;
/* Skip if not to be dumped */
if (!coninfo->dobj.dump || dopt->dataOnly)
@@ -16572,6 +16579,8 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
q = createPQExpBuffer();
delq = createPQExpBuffer();
+ foreign = tbinfo && tbinfo->relkind == RELKIND_FOREIGN_TABLE ? "FOREIGN " : "";
+
if (coninfo->contype == 'p' ||
coninfo->contype == 'u' ||
coninfo->contype == 'x')
@@ -16590,7 +16599,7 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
binary_upgrade_set_pg_class_oids(fout, q,
indxinfo->dobj.catId.oid, true);
- appendPQExpBuffer(q, "ALTER TABLE ONLY %s\n",
+ appendPQExpBuffer(q, "ALTER %sTABLE ONLY %s\n", foreign,
fmtQualifiedDumpable(tbinfo));
appendPQExpBuffer(q, " ADD CONSTRAINT %s ",
fmtId(coninfo->dobj.name));
@@ -16680,7 +16689,7 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
fmtId(indxinfo->dobj.name));
}
- appendPQExpBuffer(delq, "ALTER TABLE ONLY %s ",
+ appendPQExpBuffer(delq, "ALTER %sTABLE ONLY %s ", foreign,
fmtQualifiedDumpable(tbinfo));
appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
fmtId(coninfo->dobj.name));
@@ -16714,13 +16723,13 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
* XXX Potentially wrap in a 'SET CONSTRAINTS OFF' block so that the
* current table data is not processed
*/
- appendPQExpBuffer(q, "ALTER TABLE %s%s\n",
+ appendPQExpBuffer(q, "ALTER %sTABLE %s%s\n", foreign,
only, fmtQualifiedDumpable(tbinfo));
appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n",
fmtId(coninfo->dobj.name),
coninfo->condef);
- appendPQExpBuffer(delq, "ALTER TABLE %s%s ",
+ appendPQExpBuffer(delq, "ALTER %sTABLE %s%s ", foreign,
only, fmtQualifiedDumpable(tbinfo));
appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
fmtId(coninfo->dobj.name));
@@ -16745,13 +16754,13 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
if (coninfo->separate && coninfo->conislocal)
{
/* not ONLY since we want it to propagate to children */
- appendPQExpBuffer(q, "ALTER TABLE %s\n",
+ appendPQExpBuffer(q, "ALTER %sTABLE %s\n", foreign,
fmtQualifiedDumpable(tbinfo));
appendPQExpBuffer(q, " ADD CONSTRAINT %s %s;\n",
fmtId(coninfo->dobj.name),
coninfo->condef);
- appendPQExpBuffer(delq, "ALTER TABLE %s ",
+ appendPQExpBuffer(delq, "ALTER %sTABLE %s ", foreign,
fmtQualifiedDumpable(tbinfo));
appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
fmtId(coninfo->dobj.name));
@@ -17343,7 +17352,8 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo)
if (tginfo->tgenabled != 't' && tginfo->tgenabled != 'O')
{
- appendPQExpBuffer(query, "\nALTER TABLE %s ",
+ char * foreign = tbinfo->relkind == RELKIND_FOREIGN_TABLE? "FOREIGN " : "";
+ appendPQExpBuffer(query, "\nALTER %sTABLE %s ", foreign,
fmtQualifiedDumpable(tbinfo));
switch (tginfo->tgenabled)
{