Re: How to compare different datums within from a tuple? - Mailing list pgsql-hackers

From Anastasia Lubennikova
Subject Re: How to compare different datums within from a tuple?
Date
Msg-id CAP4vRV4M809DibcaWpA8c0hwhz1vunxXuQsqNKZDWZ+s1ge-bg@mail.gmail.com
Whole thread Raw
In response to How to compare different datums within from a tuple?  (Peter Moser <pitiz29a@gmail.com>)
Responses Re: How to compare different datums within from a tuple?  (Peter Moser <pitiz29a@gmail.com>)
List pgsql-hackers
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?

In a nutshell, there is no way to compare Datums.
Datum is an abstact data type. It's the backend internal representation of a single value of any SQL data type. 
The code using Datum has to know which type it is, since the Datum itself doesn't contain that information.
 
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 */
}

Thx,
Peter


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Maybe you can use DatumGetXXX function to extract value. For example, DatumGetInt32.
--
Best regards,
Lubennikova Anastasia

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: Raising our compiler requirements for 9.6
Next
From: Shay Rojansky
Date:
Subject: Re: statement_timeout affects query results fetching?