Re: [HACKERS] Creating operators - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [HACKERS] Creating operators
Date
Msg-id 12034.940402313@sss.pgh.pa.us
Whole thread Raw
In response to Creating operators  ("Gene Sokolov" <hook@aktrad.ru>)
List pgsql-hackers
"Gene Sokolov" <hook@aktrad.ru> writes:
> Q1:
> Let's say I want to create a '+' operator for <my own type> + int4. Do I
> really have to
> define two '+' operators, one
> <my own type> + int
> and the other
> int + <my own type>

Yes.  There's nothing compelling them to behave the same, after all
(consider '-' instead of '+').  If they do behave the same you
should indicate this with "commutator" links --- see the discussion
in the manual.

> Can I create an operator '::', such as <my own type>::double ?

You can't redefine the meaning of the typecast construct '::',
if that's what you meant.  But perhaps what you really meant
was that you want to provide a conversion from your type to
double.  For that you just make a function named 'double',
yielding double, and taking your type as input.  The typecast
code will use it automatically.

(Of course "double" is spelled "float8" in Postgres-land,
but you knew that...)
        regards, tom lane


pgsql-hackers by date:

Previous
From: Kaare Rasmussen
Date:
Subject: Re: [HACKERS] book status
Next
From: Peter Mount
Date:
Subject: RE: [HACKERS] Readline use in trouble?