Unary Operators

From: Andreas Ulbrich <andreas(dot)ulbrich(at)matheversum(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Unary Operators
Date: 2013-09-15 18:32:27
Message-ID: 5235FD3B.9000605@matheversum.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Eric B. Ridge 2013-09-15 19:24:57 Re: v9.3.0: bug with pgdump -s?
Previous Message Andres Freund 2013-09-15 18:11:39 Re: v9.3.0: bug with pgdump -s?