Unary Operators - Mailing list pgsql-general

From Andreas Ulbrich
Subject Unary Operators
Date
Msg-id 5235FD3B.9000605@matheversum.de
Whole thread Raw
Responses Re: Unary Operators  (Rowan Collins <rowan.collins@gmail.com>)
Re: Unary Operators  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Salvete!

I have the following problem.
I'd like to define the operator symbol / as a left unary operator for
reciprocal value of a number.
I did this with a C-function and all the stuff around, but it does not work.
Hiere is an extract and simplified example with the same error message
as in my complex example:

create function reciproce(float) returns float as
$$ values(1.0::float / $1) $$ language sql immutable strict;
create operator / (rightarg = float, procedure = reciproce);
select / 5.0::float;
-->
ERROR:  syntax error at or near "/"
LINE 1: select / 5.0;

This is in 9.3.0 and 9.2.4 the same.

If I take the ! as the operator all is fine:
create operator ! (rightarg = float, procedure = reciproce);
select ! 5.0::float;
-->
?column?
----------
       0.2
(1 row)

The definition seems to be equivalent:
# \do
                                  List of operators
  Schema | Name | Left arg type |  Right arg type  | Result type    |
Description
--------+------+---------------+------------------+------------------+-------------
  public | !    |               | double precision | double precision |
  public | /    |               | double precision | double precision |
(2 rows)

create operator ^- (leftarg = float, procedure = reciproce);
works too, but
create operator / (leftarg = float, procedure = reciproce);
not.

In the documentation I can't find, that / is not possible as an unary
operator.

Are there any restrictions.



pgsql-general by date:

Previous
From: Andres Freund
Date:
Subject: Re: v9.3.0: bug with pgdump -s?
Next
From: "Eric B. Ridge"
Date:
Subject: Re: v9.3.0: bug with pgdump -s?