*** doc/src/sgml/func.sgml
--- doc/src/sgml/func.sgml
***************
*** 11551,11556 **** SELECT pg_type_is_visible('myschema.widget'::regtype);
--- 11551,11560 ----
     </indexterm>
  
     <indexterm>
+     <primary>pg_typeof</primary>
+    </indexterm>
+ 
+    <indexterm>
      <primary>pg_get_keywords</primary>
     </indexterm>
  
***************
*** 11617,11622 **** SELECT pg_type_is_visible('myschema.widget'::regtype);
--- 11621,11631 ----
         <entry>get SQL name of a data type</entry>
        </row>
        <row>
+        <entry><literal><function>pg_typeof</function>(<parameter>any</parameter>)</literal></entry>
+        <entry><type>regtype</type></entry>
+        <entry>get the data type of any value</entry>
+       </row>
+       <row>
         <entry><literal><function>pg_get_keywords</function>()</literal></entry>
         <entry><type>setof record</type></entry>
         <entry>get list of SQL keywords and their categories</entry>
***************
*** 11727,11732 **** SELECT pg_type_is_visible('myschema.widget'::regtype);
--- 11736,11747 ----
    </para>
  
    <para>
+    <function>pg_typeof</function> returns the SQL name of the data type of any
+    value which is passed to it as an argument.  This can be helpful for
+    troubleshooting or dynamically constructing SQL queries.
+   </para>
+ 
+   <para>
     <function>pg_get_keywords</function> returns a set of records describing
     the SQL keywords recognized by the server. The <structfield>word</> column
     contains the keyword.  The <structfield>catcode</> column contains a
*** src/backend/utils/adt/misc.c
--- src/backend/utils/adt/misc.c
***************
*** 59,64 **** nonnullvalue(PG_FUNCTION_ARGS)
--- 59,73 ----
  }
  
  /*
+  * Return the type of the argument.
+  */
+ Datum
+ pg_typeof(PG_FUNCTION_ARGS)
+ {
+ 	PG_RETURN_OID(get_fn_expr_argtype(fcinfo->flinfo, 0));
+ }
+ 
+ /*
   * current_database()
   *	Expose the current database to the user
   */
*** src/include/catalog/catversion.h
--- src/include/catalog/catversion.h
***************
*** 53,58 ****
   */
  
  /*							yyyymmddN */
! #define CATALOG_VERSION_NO	200808311
  
  #endif
--- 53,58 ----
   */
  
  /*							yyyymmddN */
! #define CATALOG_VERSION_NO	200809031
  
  #endif
*** src/include/catalog/pg_proc.h
--- src/include/catalog/pg_proc.h
***************
*** 1121,1126 **** DESCR("does not match LIKE expression");
--- 1121,1128 ----
  DATA(insert OID =  860 (  bpchar		   PGNSP PGUID 12 1 0 0 f f t f i 1 1042 "18" _null_ _null_ _null_	char_bpchar _null_ _null_ _null_ ));
  DESCR("convert char to char()");
  
+ DATA(insert OID = 826 (  pg_typeof			PGNSP PGUID 12 1 0 0 f f f f i 1 2206  "2276" _null_ _null_ _null_  pg_typeof _null_ _null_ _null_ ));
+ DESCR("returns the type of the argument");
  DATA(insert OID = 861 ( current_database	   PGNSP PGUID 12 1 0 0 f f t f s 0 19 "" _null_ _null_ _null_ current_database _null_ _null_ _null_ ));
  DESCR("returns the current database");
  DATA(insert OID = 817 (  current_query        PGNSP PGUID 12 1 0 0 f f f f v 0 25  "" _null_ _null_ _null_  current_query _null_ _null_ _null_ ));
*** src/include/utils/builtins.h
--- src/include/utils/builtins.h
***************
*** 403,408 **** extern Datum pg_ls_dir(PG_FUNCTION_ARGS);
--- 403,409 ----
  /* misc.c */
  extern Datum nullvalue(PG_FUNCTION_ARGS);
  extern Datum nonnullvalue(PG_FUNCTION_ARGS);
+ extern Datum pg_typeof(PG_FUNCTION_ARGS);
  extern Datum current_database(PG_FUNCTION_ARGS);
  extern Datum current_query(PG_FUNCTION_ARGS);
  extern Datum pg_cancel_backend(PG_FUNCTION_ARGS);
