Re: How to compare different datums within from a tuple?

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: How to compare different datums within from a tuple?
Дата
Msg-id 55CA471D.1050801@gmx.net
обсуждение исходный текст
Ответ на How to compare different datums within from a tuple?  (Peter Moser <pitiz29a@gmail.com>)
Ответы Re: How to compare different datums within from a tuple?  (Peter Moser <pitiz29a@gmail.com>)
Список pgsql-hackers
On 8/10/15 12:36 PM, Peter Moser wrote:
> Can someone tell me, how I can compare two datum fields, when I do not
> know the data type in advance inside an executor function?
> 
> For example, "x less than y" where x and y are of various types that
> form intervals. I have found the method ExecTuplesMatch, but it is only
> for equality comparison, I think. Another one is ApplySortComparator...
> maybe that's the correct way to go?
> 
> Some code to make things clearer...
> 
> Datum x = heap_getattr(out->tts_tuple,
>         node->xpos,
>         out->tts_tupleDescriptor,
>         &isNull1);
> Datum y = slot_getattr(curr, node->ypos, &isNull2);
> 
> if (compareDatumWithCorrectMethod(x,y) < 0)
> {
>  /* do something */
> }

The tuple descriptor will contain the data type of the datum, so you can
use that to look up the default btree operator class and call the
respective operators in there.  But note that there is no single notion
of comparison in the system.  Comparison depends on operator class,
access method, possibly collation, null value treatment.  Some types
don't support comparison beyond equality.  A robust patch would need to
take that into account.




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

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: WIP: SCRAM authentication
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: pg_dump and search_path