Search Postgresql Archives

Unary Operators

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.



--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux