Re: test datatype for ANY

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: test datatype for ANY
Дата
Msg-id 20050211202738.GA32941@winnie.fuhr.org
обсуждение исходный текст
Ответ на Re: test datatype for ANY  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: test datatype for ANY  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
On Fri, Feb 11, 2005 at 02:32:31PM -0500, Tom Lane wrote:

> There are some limited cases you could handle in plpgsql using the
> polymorphic-functions stuff (ie, ANYELEMENT not ANY) but it still has
> no concept of a run-time type test.

Eh?  What am I misunderstanding then?  The following done in 8.0.1:

CREATE FUNCTION argtype(param anyelement) RETURNS text AS $$
BEGIN
    IF param IS OF (integer) THEN
    RETURN 'integer';
    ELSIF param IS OF (numeric) THEN
    RETURN 'numeric';
    ELSIF param IS OF (boolean) THEN
    RETURN 'boolean';
    ELSIF param IS OF (text) THEN
    RETURN 'text';
    ELSIF param IS OF (date) THEN
    RETURN 'date';
    END IF;

   RETURN 'something else';
END;
$$ LANGUAGE plpgsql IMMUTABLE;

SELECT argtype(1);
 argtype
---------
 integer

SELECT argtype(1.2);
 argtype
---------
 numeric

SELECT argtype('test'::text);
 argtype
---------
 text

SELECT argtype(true);
 argtype
---------
 boolean

CREATE TABLE foo (id integer, foodate date);
INSERT INTO foo VALUES (1, current_date);
SELECT argtype(id) AS idtype, argtype(foodate) AS foodatetype FROM foo;
 idtype  | foodatetype
---------+-------------
 integer | date

SELECT argtype(x) FROM (SELECT foodate FROM foo) AS s(x);
 argtype
---------
 date

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

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

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