Re: Help with casting and comparing. - Mailing list pgsql-hackers

From Martijn van Oosterhout
Subject Re: Help with casting and comparing.
Date
Msg-id 20060628144443.GB3521@svana.org
Whole thread Raw
In response to Help with casting and comparing.  (Tzahi Fadida <Tzahi.ML@gmail.com>)
Responses Re: Help with casting and comparing.  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Wed, Jun 28, 2006 at 03:25:57PM +0300, Tzahi Fadida wrote:
> Hi,
>
> I need help finding out how to determine if two types are equality compatible
> and compare them.

<snip>

> Currently i only allow two values only of the same type but i wish to allow
> to compare values like "20.2"=?20.2 or 20=?20.0 etc...
>
> The first step is to find out if two attributes are equality and casting
> compatible, i.e., if one type can be cast to the other type so they can be
> compared. Or, just equality compatible and the casting is done somehow behind
> the scene.

There's two ways an equality could work. For example, there are
equality operators that take parameters of different types. That's the
easy case. Then you have binary compatable types, and then types with
actual conversion functions.

Fortunatly the backend contains functions that do all this already.
Check out parser/parse_oper.c, in particular oper() and
compatable_oper().

You may have to be prepared to handle a parsetree to do the actual
work.

/* oper() -- search for a binary operator* Given operator name, types of arg1 and arg2, return oper struct.**
IMPORTANT:the returned operator (if any) is only promised to be* coercion-compatible with the input datatypes.  Do not
usethis if* you need an exact- or binary-compatible match; see compatible_oper. 
...etc...

Hope this helps,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: SO_SNDBUF size is small on win32?
Next
From: Phil Frost
Date:
Subject: optimizing constant quals within outer joins