Make pg_tablespace_location(0) return the database's default tablespace.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 11 Apr 2012 01:42:46 +0000 (21:42 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 11 Apr 2012 01:43:14 +0000 (21:43 -0400)
This definition is convenient when applying the function to the
reltablespace column of pg_class, since that's what zero means there;
and it doesn't interfere with any other plausible use of the function.
Per gripe from Bruce Momjian.

src/backend/utils/adt/misc.c

index 6a1b47714722ca4a4814056fd007e27721bf80f1..6bd7d531bbc8cb516e7ce24f80e87929bc744998 100644 (file)
@@ -335,7 +335,15 @@ pg_tablespace_location(PG_FUNCTION_ARGS)
        int             rllen;
 
        /*
-        * Return empty string for our default tablespaces
+        * It's useful to apply this function to pg_class.reltablespace, wherein
+        * zero means "the database's default tablespace".  So, rather than
+        * throwing an error for zero, we choose to assume that's what is meant.
+        */
+       if (tablespaceOid == InvalidOid)
+               tablespaceOid = MyDatabaseTableSpace;
+
+       /*
+        * Return empty string for the cluster's default tablespaces
         */
        if (tablespaceOid == DEFAULTTABLESPACE_OID ||
                tablespaceOid == GLOBALTABLESPACE_OID)