Search Postgresql Archives

Re: test datatype for ANY

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Feb 11, 2005 at 08:40:53PM +0000, NosyMan wrote:
> 
> How can I test the type of a parameter passed to a function via ANY data type? 
> I want something like this:
> 
> CREATE OR REPLACE FUNCTION myfunction(_param ANY) RETURNS INTEGER AS $$
> 	BEGIN
> 		IF "_param IS OF INTEGER TYPE" THEN
> 			-- do something with INTEGER
> 		END IF;

PostgreSQL has an undocumented IS OF construct:

http://archives.postgresql.org/pgsql-general/2005-01/msg00398.php

Example:

  IF param IS OF (integer) THEN
      -- do integer stuff
  ELSIF param IS OF (boolean) THEN
      -- do boolean stuff
  END IF;

Since IS OF is undocumented, I'd be careful about using it.  I don't
know what plans the developers have for it, but I doubt they'll
feel sorry for you if your code breaks because they removed it or
changed its behavior.

See also the coltype() function I posted as part of the same thread
that mentioned IS OF:

http://archives.postgresql.org/pgsql-general/2005-01/msg00390.php

Using coltype(), the above code would look like this:

  IF coltype(param) = 'integer'::regtype THEN
      -- do integer stuff
  ELSIF coltype(param) = 'boolean'::regtype THEN
      -- do boolean stuff
  END IF;

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
      joining column's datatypes do not match

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux