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

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Reply via email to