I noticed there is an SPI API function to get the name of a specified Relation, but no similar function to get the Relation's namespace. Attached is a patch that implements SPI_getnspname().

I wasn't sure if I should refer to the relation's "schema" or its "namespace"; my feeling was that SPI is sufficiently close to the internals that we should use the internal term, which is namespace.

Barring any objections, I'll apply this later today.

-Neil
Index: doc/src/sgml/spi.sgml
===================================================================
RCS file: /var/lib/cvs/pgsql/doc/src/sgml/spi.sgml,v
retrieving revision 1.39
diff -c -r1.39 spi.sgml
*** doc/src/sgml/spi.sgml	22 Jan 2005 22:56:36 -0000	1.39
--- doc/src/sgml/spi.sgml	24 Mar 2005 01:52:11 -0000
***************
*** 2153,2158 ****
--- 2153,2212 ----
   </refsect1>
  </refentry>
  
+ <refentry id="spi-spi-getnspname">
+  <refmeta>
+   <refentrytitle>SPI_getnspname</refentrytitle>
+  </refmeta>
+ 
+  <refnamediv>
+   <refname>SPI_getnspname</refname>
+   <refpurpose>return the namespace of the specified relation</refpurpose>
+  </refnamediv>
+ 
+  <indexterm><primary>SPI_getnspname</primary></indexterm>
+ 
+  <refsynopsisdiv>
+ <synopsis>
+ char * SPI_getnspname(Relation <parameter>rel</parameter>)
+ </synopsis>
+  </refsynopsisdiv>
+ 
+  <refsect1>
+   <title>Description</title>
+ 
+   <para>
+    <function>SPI_getnspname</function> returns a copy of the name of
+    the namespace that the specified <structname>Relation</structname>
+    belongs to. This is equivalent to the relation's schema. You should
+    <function>pfree</function> the return value of this function when
+    you are finished with it.
+   </para>
+  </refsect1>
+ 
+  <refsect1>
+   <title>Arguments</title>
+ 
+   <variablelist>
+    <varlistentry>
+     <term><literal>Relation <parameter>rel</parameter></literal></term>
+     <listitem>
+      <para>
+       input relation
+      </para>
+     </listitem>
+    </varlistentry>
+   </variablelist>
+  </refsect1>
+ 
+  <refsect1>
+   <title>Return Value</title>
+ 
+   <para>
+    The name of the specified relation's namespace.
+   </para>
+  </refsect1>
+ </refentry>
+ 
   </sect1>
  
   <sect1 id="spi-memory">
Index: src/backend/executor/spi.c
===================================================================
RCS file: /var/lib/cvs/pgsql/src/backend/executor/spi.c,v
retrieving revision 1.135
diff -c -r1.135 spi.c
*** src/backend/executor/spi.c	16 Mar 2005 21:38:08 -0000	1.135
--- src/backend/executor/spi.c	23 Mar 2005 09:08:42 -0000
***************
*** 760,765 ****
--- 760,771 ----
  	return pstrdup(RelationGetRelationName(rel));
  }
  
+ char *
+ SPI_getnspname(Relation rel)
+ {
+     return get_namespace_name(RelationGetNamespace(rel));
+ }
+ 
  void *
  SPI_palloc(Size size)
  {
Index: src/include/executor/spi.h
===================================================================
RCS file: /var/lib/cvs/pgsql/src/include/executor/spi.h,v
retrieving revision 1.50
diff -c -r1.50 spi.h
*** src/include/executor/spi.h	16 Nov 2004 18:10:13 -0000	1.50
--- src/include/executor/spi.h	23 Mar 2005 09:09:50 -0000
***************
*** 113,118 ****
--- 113,119 ----
  extern char *SPI_gettype(TupleDesc tupdesc, int fnumber);
  extern Oid	SPI_gettypeid(TupleDesc tupdesc, int fnumber);
  extern char *SPI_getrelname(Relation rel);
+ extern char *SPI_getnspname(Relation rel);
  extern void *SPI_palloc(Size size);
  extern void *SPI_repalloc(void *pointer, Size size);
  extern void SPI_pfree(void *pointer);
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq

Reply via email to