1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
5 >Function Overloading</TITLE
8 CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
10 HREF="mailto:pgsql-docs@postgresql.org"><LINK
12 TITLE="PostgreSQL 7.4.1 Documentation"
13 HREF="index.html"><LINK
16 HREF="extend.html"><LINK
18 TITLE="C-Language Functions"
19 HREF="xfunc-c.html"><LINK
21 TITLE="User-Defined Aggregates"
22 HREF="xaggr.html"><LINK
25 HREF="stylesheet.css"><META
27 CONTENT="2003-12-22T03:48:47"></HEAD
33 SUMMARY="Header navigation table"
43 >PostgreSQL 7.4.1 Documentation</TH
67 >Chapter 33. Extending <ACRONYM
99 >33.8. Function Overloading</A
105 > More than one function may be defined with the same SQL name, so long
106 as the arguments they take are different. In other words,
107 function names can be <I
111 query is executed, the server will determine which function to
112 call from the data types and the number of the provided arguments.
113 Overloading can also be used to simulate functions with a variable
114 number of arguments, up to a finite maximum number.
117 > A function may also have the same name as an attribute. (Recall
120 >attribute(table)</TT
125 >.) In the case that there is an
126 ambiguity between a function on a complex type and an attribute of
127 the complex type, the attribute will always be used.
130 > When creating a family of overloaded functions, one should be
131 careful not to create ambiguities. For instance, given the
134 CLASS="PROGRAMLISTING"
135 >CREATE FUNCTION test(int, real) RETURNS ...
136 CREATE FUNCTION test(smallint, double precision) RETURNS ...</PRE
138 it is not immediately clear which function would be called with
139 some trivial input like <TT
143 currently implemented resolution rules are described in
147 >, but it is unwise to design a system that subtly
148 relies on this behavior.
151 > When overloading C-language functions, there is an additional
152 constraint: The C name of each function in the family of
153 overloaded functions must be different from the C names of all
154 other functions, either internal or dynamically loaded. If this
155 rule is violated, the behavior is not portable. You might get a
156 run-time linker error, or one of the functions will get called
157 (usually the internal one). The alternative form of the
161 > clause for the SQL <TT
165 > command decouples the SQL function name from
166 the function name in the C source code. E.g.,
168 CLASS="PROGRAMLISTING"
169 >CREATE FUNCTION test(int) RETURNS int
175 CREATE FUNCTION test(int, int) RETURNS int
182 The names of the C functions here reflect one of many possible conventions.
190 SUMMARY="Footer navigation table"
229 >C-Language Functions</TD
243 >User-Defined Aggregates</TD