Skip site navigation (1) Skip section navigation (2)

Re: Function proposal to find the type of a datum

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 (view raw or flat)
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

In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2007-02-02 08:06:19
Subject: Re: Function proposal to find the type of a datum
Previous:From: Pavel StehuleDate: 2007-02-02 07:47:22
Subject: ToDo: add documentation for operator IS OF

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group