Skip to content

Commit 0461b66

Browse files
committed
Fix pg_dump to not emit invalid SQL for an empty operator class.
If an operator class has no operators or functions, and doesn't need a STORAGE clause, we emitted "CREATE OPERATOR CLASS ... AS ;" which is syntactically invalid. Fix by forcing a STORAGE clause to be emitted anyway in this case. (At some point we might consider changing the grammar to allow CREATE OPERATOR CLASS without an opclass_item_list. But probably we'd want to omit the AS in that case, so that wouldn't fix this pg_dump issue anyway.) It's been like this all along, so back-patch to all supported branches. Daniel Gustafsson, tweaked by me to avoid a dangling-pointer bug Discussion: https://postgr.es/m/D9E5FC64-7A37-4F3D-B946-7E4FB468F88A@yesql.se
1 parent 9c34a05 commit 0461b66

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12440,7 +12440,8 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
1244012440
i_opcfamilynsp = PQfnumber(res, "opcfamilynsp");
1244112441
i_amname = PQfnumber(res, "amname");
1244212442

12443-
opcintype = PQgetvalue(res, 0, i_opcintype);
12443+
/* opcintype may still be needed after we PQclear res */
12444+
opcintype = pg_strdup(PQgetvalue(res, 0, i_opcintype));
1244412445
opckeytype = PQgetvalue(res, 0, i_opckeytype);
1244512446
opcdefault = PQgetvalue(res, 0, i_opcdefault);
1244612447
/* opcfamily will still be needed after we PQclear res */
@@ -12674,6 +12675,15 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
1267412675

1267512676
PQclear(res);
1267612677

12678+
/*
12679+
* If needComma is still false it means we haven't added anything after
12680+
* the AS keyword. To avoid printing broken SQL, append a dummy STORAGE
12681+
* clause with the same datatype. This isn't sanctioned by the
12682+
* documentation, but actually DefineOpClass will treat it as a no-op.
12683+
*/
12684+
if (!needComma)
12685+
appendPQExpBuffer(q, "STORAGE %s", opcintype);
12686+
1267712687
appendPQExpBufferStr(q, ";\n");
1267812688

1267912689
appendPQExpBuffer(labelq, "OPERATOR CLASS %s",
@@ -12701,6 +12711,8 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
1270112711
opcinfo->dobj.namespace->dobj.name, opcinfo->rolname,
1270212712
opcinfo->dobj.catId, 0, opcinfo->dobj.dumpId);
1270312713

12714+
free(opcintype);
12715+
free(opcfamily);
1270412716
free(amname);
1270512717
destroyPQExpBuffer(query);
1270612718
destroyPQExpBuffer(q);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy