Re: Function proposal to find the type of a datum

Поиск
Список
Период
Сортировка
От Kate F
Тема Re: Function proposal to find the type of a datum
Дата
Msg-id 20070202075108.GB390@cats.meow.at
обсуждение исходный текст
Ответ на Re: Function proposal to find the type of a datum  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Function proposal to find the type of a datum
Список 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) THENt := 'INTEGER';
ELSE IF a IS OF (TEXT) THENt := 'TEXT';
ELSE IF a IS OF (REAL) THENt := '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


В списке pgsql-hackers по дате отправления:

Предыдущее
От: "Pavel Stehule"
Дата:
Сообщение: ToDo: add documentation for operator IS OF
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Function proposal to find the type of a datum