]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix pg_dump to add the required OPERATOR() decoration to schema-qualified
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 9 Jan 2006 21:16:37 +0000 (21:16 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 9 Jan 2006 21:16:37 +0000 (21:16 +0000)
operator names.  This is needed when dumping operator definitions that have
COMMUTATOR (or similar) links to operators in other schemas.
Apparently Daniel Whitter is the first person ever to try this :-(

src/bin/pg_dump/pg_dump.c

index afbb7173d57c4851464312a6ed2d9a5296435d40..f71d41a2394fd46761cf3046c0e92d493be811f1 100644 (file)
@@ -12,7 +12,7 @@
  *     by PostgreSQL
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.400.4.5 2005/06/07 14:05:01 tgl Exp $
+ *       $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.400.4.6 2006/01/09 21:16:37 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -5728,9 +5728,10 @@ convertRegProcReference(const char *proc)
  *
  * Returns what to print, or NULL to print nothing
  *
- * In 7.3 the input is a REGOPERATOR display; we have to strip the
- * argument-types part.  In prior versions, the input is just a
- * numeric OID, which we search our operator list for.
+ * In 7.3 and up the input is a REGOPERATOR display; we have to strip the
+ * argument-types part, and add OPERATOR() decoration if the name is
+ * schema-qualified.  In older versions, the input is just a numeric OID,
+ * which we search our operator list for.
  */
 static const char *
 convertOperatorReference(const char *opr)
@@ -5744,23 +5745,34 @@ convertOperatorReference(const char *opr)
        if (g_fout->remoteVersion >= 70300)
        {
                char       *name;
-               char       *paren;
+               char       *oname;
+               char       *ptr;
                bool            inquote;
+               bool            sawdot;
 
                name = strdup(opr);
-               /* find non-double-quoted left paren */
+               /* find non-double-quoted left paren, and check for non-quoted dot */
                inquote = false;
-               for (paren = name; *paren; paren++)
+               sawdot = false;
+               for (ptr = name; *ptr; ptr++)
                {
-                       if (*paren == '(' && !inquote)
+                       if (*ptr == '"')
+                               inquote = !inquote;
+                       else if (*ptr == '.' && !inquote)
+                               sawdot = true;
+                       else if (*ptr == '(' && !inquote)
                        {
-                               *paren = '\0';
+                               *ptr = '\0';
                                break;
                        }
-                       if (*paren == '"')
-                               inquote = !inquote;
                }
-               return name;
+               /* If not schema-qualified, don't need to add OPERATOR() */
+               if (!sawdot)
+                       return name;
+               oname = malloc(strlen(name) + 11);
+               sprintf(oname, "OPERATOR(%s)", name);
+               free(name);
+               return oname;
        }
 
        oprInfo = findOprByOid(atooid(opr));