From: | Michael Fuhr <mike(at)fuhr(dot)org> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | NosyMan <nosyman(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: test datatype for ANY |
Date: | 2005-02-11 20:27:38 |
Message-ID: | 20050211202738.GA32941@winnie.fuhr.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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/
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2005-02-11 20:37:01 | Re: test datatype for ANY |
Previous Message | benjamin jacob | 2005-02-11 20:16:50 | data duplication |