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/