Re: test datatype for ANY

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

[ thinks about that for awhile... ]  Oh, I see.  The reason this appears
to work is that plpgsql compiles a separate version of the function for
each actual parameter datatype that is used in a given session.  So in
your example, you get a separate version for integer, numeric, etc.
Within each such version IS OF yields constants, but it "works right"
anyway.

I'm not sure if you can actually tell the difference between this
behavior and a true runtime test; except maybe that the backend would
get a bit bloated if you tried it on hundreds of different types in one
session.

            regards, tom lane

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

Предыдущее
От: Michael Fuhr
Дата:
Сообщение: Re: test datatype for ANY
Следующее
От: Harald Fuchs
Дата:
Сообщение: Re: Understanding EXPLAIN ANALYZE output