summaryrefslogtreecommitdiff
path: root/doc/src/sgml/xoper.sgml
diff options
context:
space:
mode:
authorThomas G. Lockhart <lockhart@fourpalms.org>1998-03-01 08:16:16 +0000
committerThomas G. Lockhart <lockhart@fourpalms.org>1998-03-01 08:16:16 +0000
commitc8cfb0cea88fec22f5aa0582fe846b46baf77eb1 (patch)
treeeb009c5363c2d5d8f7d99e6264c2a282d4ad7e58 /doc/src/sgml/xoper.sgml
parent878531f1ac8a288fdd04c7c41ac2f02d2506bcb7 (diff)
downloadpostgresql-c8cfb0cea88fec22f5aa0582fe846b46baf77eb1.tar.gz
SGML source for new documentation.
Diffstat (limited to 'doc/src/sgml/xoper.sgml')
-rw-r--r--doc/src/sgml/xoper.sgml52
1 files changed, 52 insertions, 0 deletions
diff --git a/doc/src/sgml/xoper.sgml b/doc/src/sgml/xoper.sgml
new file mode 100644
index 0000000000..fa5e7342f6
--- /dev/null
+++ b/doc/src/sgml/xoper.sgml
@@ -0,0 +1,52 @@
+<Chapter>
+<Title>Extending <Acronym>SQL</Acronym>: Operators</Title>
+
+<Para>
+ <ProductName>Postgres</ProductName> supports left unary, right unary and binary
+ operators. Operators can be overloaded, or re-used
+ with different numbers and types of arguments. If
+ there is an ambiguous situation and the system cannot
+ determine the correct operator to use, it will return
+ an error and you may have to typecast the left and/or
+ right operands to help it understand which operator you
+ meant to use.
+ To create an operator for adding two complex numbers
+ can be done as follows. First we need to create a
+ function to add the new types. Then, we can create the
+ operator with the function.
+
+<ProgramListing>
+ CREATE FUNCTION complex_add(complex, complex)
+ RETURNS complex
+ AS '$PWD/obj/complex.so'
+ LANGUAGE 'c';
+
+ CREATE OPERATOR + (
+ leftarg = complex,
+ rightarg = complex,
+ procedure = complex_add,
+ commutator = +
+ );
+</ProgramListing>
+</Para>
+
+<Para>
+ We've shown how to create a binary operator here. To
+ create unary operators, just omit one of leftarg (for
+ left unary) or rightarg (for right unary).
+ If we give the system enough type information, it can
+ automatically figure out which operators to use.
+
+<ProgramListing>
+ SELECT (a + b) AS c FROM test_complex;
+
+ +----------------+
+ |c |
+ +----------------+
+ |(5.2,6.05) |
+ +----------------+
+ |(133.42,144.95) |
+ +----------------+
+</ProgramListing>
+</Para>
+</Chapter>