From: | Kate F <kate(at)cats(dot)meow(dot)at> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Function proposal to find the type of a datum |
Date: | 2007-02-02 07:51:08 |
Message-ID: | 20070202075108.GB390@cats.meow.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Fri, Feb/ 2/07 02:41:15AM -0500, Tom Lane wrote:
>
> > Meanwhile, I still think the function David proposed is a worthy
> > addition (and I still have a user-case for it!), as using just the OF
> > operator for something similar, one would have to explictly test
> > against every type required.
>
> Um, but what would you do differently with an OID result? The nice
> thing about the SQL-spec syntax is that it avoids depending on anything
> so implementation-specific as a pg_type OID. So if it covers the
> territory then I'd be inclined to go that way. What useful
> functionality does it lack?
There are two differences here. I did try to explain these in my
previous mail, but perhaps I wasn't clear enough. Firstly:
Substitute the name of the type (as TEXT) if you think that's more
appropiate.
The difference between OF and this function is that this function is
pulling the type from the datum, rather than explicitly testing it
against types the user suggests. If I wanted to find the type of x
using OF, I would have to check it for all types which interest me:
IF a IS OF (INTEGER) THEN
t := 'INTEGER';
ELSE IF a IS OF (TEXT) THEN
t := 'TEXT';
ELSE IF a IS OF (REAL) THEN
t := 'REAL';
...
and so on. Versus:
t := pg_type_of(a);
Secondly, the semantics are different: OF yields the type the datum
currently is; pg_type_of() (perhaps it should be renamed?) returns the
most appropiate type to which the datum may be cast, if I understand
get_fn_expr_argtype() correctly.
Regards,
--
Kate
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2007-02-02 08:06:19 | Re: Function proposal to find the type of a datum |
Previous Message | Pavel Stehule | 2007-02-02 07:47:22 | ToDo: add documentation for operator IS OF |