Re: [HACKERS] Creating operators

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Gene Sokolov" <hook(at)aktrad(dot)ru>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] Creating operators
Date: 1999-10-20 06:51:53
Message-ID: 12034.940402313@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"Gene Sokolov" <hook(at)aktrad(dot)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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Mount 1999-10-20 07:08:15 RE: [HACKERS] Readline use in trouble?
Previous Message Kaare Rasmussen 1999-10-20 06:17:37 Re: [HACKERS] book status