Search Postgresql Archives

Re: test datatype for ANY

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

 



Michael Fuhr <mike@xxxxxxxx> 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

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

[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