Attached.

There is no other way at the moment to get the tablespace name of an
object in psql.

We get information for tables, index, sequences and toast tables.

We should probably do this for schemas too...

Gavin
Index: src/bin/psql/common.h
===================================================================
RCS file: /usr/local/cvsroot/pgsql-server/src/bin/psql/common.h,v
retrieving revision 1.35
diff -2 -c -r1.35 common.h
*** src/bin/psql/common.h       19 Apr 2004 17:42:58 -0000      1.35
--- src/bin/psql/common.h       24 Jun 2004 03:16:02 -0000
***************
*** 21,24 ****
--- 21,27 ----
  #endif
  
+ #define atooid(x)  ((Oid) strtoul((x), NULL, 10))
+ 
+ 
  /*
   * Safer versions of some standard C library functions. If an
Index: src/bin/psql/describe.c
===================================================================
RCS file: /usr/local/cvsroot/pgsql-server/src/bin/psql/describe.c,v
retrieving revision 1.99
diff -2 -c -r1.99 describe.c
*** src/bin/psql/describe.c     18 Jun 2004 06:14:04 -0000      1.99
--- src/bin/psql/describe.c     24 Jun 2004 10:59:32 -0000
***************
*** 40,43 ****
--- 40,46 ----
                                   const char *altnamevar, const char *visibilityrule);
  
+ static void add_tablespace_footer(char relkind, Oid tablespace, 
+               char **footers, int *count, PQExpBufferData buf);
+ 
  /*----------------
   * Handlers for various slash commands displaying some sort of list
***************
*** 683,686 ****
--- 686,690 ----
                bool            hasrules;
                bool        hasoids;
+               Oid                     tablespace;
        }                       tableinfo;
        bool            show_modifiers = false;
***************
*** 695,699 ****
        /* Get general table info */
        printfPQExpBuffer(&buf,
!        "SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules, 
relhasoids\n"
                                          "FROM pg_catalog.pg_class WHERE oid = '%s'",
                                          oid);
--- 699,704 ----
        /* Get general table info */
        printfPQExpBuffer(&buf,
!        "SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules, \n" 
!                                       "relhasoids, reltablespace \n"
                                          "FROM pg_catalog.pg_class WHERE oid = '%s'",
                                          oid);
***************
*** 718,721 ****
--- 723,727 ----
        tableinfo.hasrules = strcmp(PQgetvalue(res, 0, 4), "t") == 0;
        tableinfo.hasoids = strcmp(PQgetvalue(res, 0, 5), "t") == 0;
+       tableinfo.tablespace = atooid(PQgetvalue(res, 0, 6));
        PQclear(res);
  
***************
*** 869,873 ****
  
        /* Make footers */
!       if (tableinfo.relkind == 'i')
        {
                /* Footer information about an index */
--- 875,895 ----
  
        /* Make footers */
!       if(tableinfo.relkind == 'S' || tableinfo.relkind == 't')
!       {
!               /*
!                * We can handle TOAST and sequences together, as the only
!                * footer is tablespace
!                */
!               int                     count_footers = 0;
! 
!               footers = pg_malloc_zero(3 * sizeof(*footers));
! 
! #ifndef WIN32
!         add_tablespace_footer(tableinfo.relkind, tableinfo.tablespace,
!               &footers[0], &count_footers, buf);
! #endif
!               footers[count_footers] = NULL;
!       }
!       else if (tableinfo.relkind == 'i')
        {
                /* Footer information about an index */
***************
*** 898,901 ****
--- 920,924 ----
                        char       *indtable = PQgetvalue(result, 0, 4);
                        char       *indpred = PQgetvalue(result, 0, 5);
+                       int                     count_footers = 0;
  
                        if (strcmp(indisprimary, "t") == 0)
***************
*** 917,923 ****
                                appendPQExpBuffer(&tmpbuf, _(", CLUSTER"));
  
!                       footers = pg_malloc_zero(2 * sizeof(*footers));
!                       footers[0] = pg_strdup(tmpbuf.data);
!                       footers[1] = NULL;
                }
  
--- 940,951 ----
                                appendPQExpBuffer(&tmpbuf, _(", CLUSTER"));
  
!                       footers = pg_malloc_zero(4 * sizeof(*footers));
!                       footers[count_footers++] = pg_strdup(tmpbuf.data);
! #ifndef WIN32
!               add_tablespace_footer(tableinfo.relkind, tableinfo.tablespace,
!               footers, &count_footers, tmpbuf);
! #endif
!                       footers[count_footers] = NULL;
! 
                }
  
***************
*** 1104,1108 ****
                        inherits_count = PQntuples(result6);
  
!               footers = pg_malloc_zero((index_count + check_count + rule_count + 
trigger_count + foreignkey_count + inherits_count + 6)
                                                                 * sizeof(*footers));
  
--- 1132,1136 ----
                        inherits_count = PQntuples(result6);
  
!               footers = pg_malloc_zero((index_count + check_count + rule_count + 
trigger_count + foreignkey_count + inherits_count + 7 + 1)
                                                                 * sizeof(*footers));
  
***************
*** 1237,1240 ****
--- 1265,1272 ----
                }
  
+ #ifndef WIN32
+               add_tablespace_footer(tableinfo.relkind, tableinfo.tablespace,
+                       footers, &count_footers, buf);
+ #endif
                /* end of list marker */
                footers[count_footers] = NULL;
***************
*** 1287,1290 ****
--- 1319,1361 ----
  }
  
+ 
+ static void
+ add_tablespace_footer(char relkind, Oid tablespace, char **footers, 
+               int *count, PQExpBufferData buf)
+ {
+ #ifndef WIN32
+       /* relkinds for which we support tablespaces */
+       if(relkind == 'r' || relkind == 'S' || relkind == 'i' || relkind == 't')
+       {
+               /* default */
+               if(tablespace == 0)
+               {
+                       printfPQExpBuffer(&buf, _("Tablespace:"));
+                       footers[(*count)++] = pg_strdup(buf.data);
+                       footers[(*count)++] = pg_strdup("    \"pg_default\"");
+               }
+               else
+               {
+                       PGresult   *result1 = NULL;
+                       printfPQExpBuffer(&buf, "SELECT spcname FROM pg_tablespace \n"
+                               "WHERE oid = '%u';", tablespace);
+                       result1 = PSQLexec(buf.data, false);
+               if (!result1)
+                               return;
+                       /* Should always be the case, but.... */
+                       if(PQntuples(result1) > 0)
+                       {
+                               printfPQExpBuffer(&buf, _("Tablespace:"));
+                               footers[(*count)++] = pg_strdup(buf.data);
+                               printfPQExpBuffer(&buf, _("    \"%s\""),
+                                                                         
PQgetvalue(result1, 0, 0));
+       
+                               footers[(*count)++] = pg_strdup(buf.data);
+                       }
+                       PQclear(result1);
+               }
+       }
+ #endif
+ }
  
  /*
Index: src/bin/psql/large_obj.c
===================================================================
RCS file: /usr/local/cvsroot/pgsql-server/src/bin/psql/large_obj.c,v
retrieving revision 1.31
diff -2 -c -r1.31 large_obj.c
*** src/bin/psql/large_obj.c    29 Nov 2003 19:52:06 -0000      1.31
--- src/bin/psql/large_obj.c    24 Jun 2004 03:16:26 -0000
***************
*** 17,23 ****
  
  
- #define atooid(x)  ((Oid) strtoul((x), NULL, 10))
- 
- 
  /*
   * Prepare to do a large-object operation.    We *must* be inside a transaction
--- 17,20 ----
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Reply via email to