2 <Title>Extending <Acronym>SQL</Acronym>: Operators</Title>
5 <ProductName>Postgres</ProductName> supports left unary, right unary and binary
6 operators. Operators can be overloaded, or re-used
7 with different numbers and types of arguments. If
8 there is an ambiguous situation and the system cannot
9 determine the correct operator to use, it will return
10 an error and you may have to typecast the left and/or
11 right operands to help it understand which operator you
13 To create an operator for adding two complex numbers
14 can be done as follows. First we need to create a
15 function to add the new types. Then, we can create the
16 operator with the function.
19 CREATE FUNCTION complex_add(complex, complex)
21 AS '$PWD/obj/complex.so'
27 procedure = complex_add,
34 We've shown how to create a binary operator here. To
35 create unary operators, just omit one of leftarg (for
36 left unary) or rightarg (for right unary).
37 If we give the system enough type information, it can
38 automatically figure out which operators to use.
41 SELECT (a + b) AS c FROM test_complex;