Subject: define operator

From: Wolf Guddat <[email-masked]>
Date: Fri, 25 Jun 93 11:33:56 MESZ

Hi everybody,

I'm trying to define some operators on my adt-types. Binary operators
don't make problems, but unary do.

I think the postgres "define operator" command doesn't work
correct. 
Or am I doing something wrong?

Having written and defined an operator-adt-function called "my_func"
           MYTYPE *my_func (MYTYPE *)
i tried to define the following operator ++.

define operator ++
(arg1 = MYTYPE,
procedure = my_func
)

1.)
-- How will the backend know if it is a right-unary or a left-unary operator?
(I don't know how to tell it the backend, perhaps the reference-manual is incomplete)
Working with this operator is impossible, the backend always misses
the left operand, when i send the following query:

append I (i = ++"data"::MYTYPE)

2.)
Consulting the system-catalog pg_operator shows the mistake.
oprkind = l                  ## this means left-unary
oprleft = oid_of_my_type     ## left operand type
oprright = 0                 ## right operand type
oprresult = oid_of_my_type   ## result type

-- How can a left-unary operator have a left operand and no right operand?

3.)
Ok, then i tried this:
First i removed my operator.
Second i appended a tuple in the pg_operator catalog by my own
with oprname = "++"
     oprkind=l
     oprleft=0
     oprright=oid_of_my_type
     opr_result=oid_of_my_type
now it works fine.

4.)
Trying the same with
  oprname = "+"
don't works ("parser: syntax error at or near +", when doing an 
	     append I (i= +"data"::MYTYPE) 
            )

Has someone of you similar problems? If so i would be glad if you contact me.

Bye Wolf

---

From: [email-masked] (Paul M. Aoki)
Date: Fri, 25 Jun 93 07:48:16 -0700

Wolf Guddat <[email-masked]> writes:
> define operator ++ (arg1 = MYTYPE, procedure = my_func )

this is a problem that avi pfeffer fixed a couple of months ago.
the new "define operator" man page says, for a right-unary, define 
arg1, for a left-unary, define arg2, and for a binary, define both.
it would make more sense if "arg1" and "arg2" were named "leftarg"
and "rightarg" or something..

> -- How can a left-unary operator have a left operand and no right operand?

you're exactly right.  it's been like that back to the dawn of time
(or the beginning of the RCS history, same thing :-)  goes to show 
how many people define unary operators.. anyway, avi fixed this as well.

with respect to unary +: i think this is a crock in the grammar.
the only valid single-character operator names appear to be: ~!@#%^&`?
e.g., you can't define a new single-character operator with +-*/=<> ..
--
  Paul M. Aoki  |  CS Div., Dept. of EECS, UCB  |  [email-masked]
                |  Berkeley, CA 94720           |  ...!uunet!ucbvax!aoki