Re: test datatype for ANY

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: test datatype for ANY
Дата
Msg-id 20050211190622.GA32524@winnie.fuhr.org
обсуждение исходный текст
Ответ на test datatype for ANY  (NosyMan <nosyman@gmail.com>)
Ответы Re: test datatype for ANY  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
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/

В списке pgsql-general по дате отправления:

Предыдущее
От: "Ignacio Colmenero"
Дата:
Сообщение: ERROR: control reached end of function without RETURN
Следующее
От: Tom Lane
Дата:
Сообщение: Re: ERROR: control reached end of function without RETURN