OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I686LINUX / util / I686LINUX / doc / postgresql / html / xfunc-overload.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <HTML
3 ><HEAD
4 ><TITLE
5 >Function Overloading</TITLE
6 ><META
7 NAME="GENERATOR"
8 CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
9 REV="MADE"
10 HREF="mailto:pgsql-docs@postgresql.org"><LINK
11 REL="HOME"
12 TITLE="PostgreSQL 7.4.1 Documentation"
13 HREF="index.html"><LINK
14 REL="UP"
15 TITLE="Extending SQL"
16 HREF="extend.html"><LINK
17 REL="PREVIOUS"
18 TITLE="C-Language Functions"
19 HREF="xfunc-c.html"><LINK
20 REL="NEXT"
21 TITLE="User-Defined Aggregates"
22 HREF="xaggr.html"><LINK
23 REL="STYLESHEET"
24 TYPE="text/css"
25 HREF="stylesheet.css"><META
26 NAME="creation"
27 CONTENT="2003-12-22T03:48:47"></HEAD
28 ><BODY
29 CLASS="SECT1"
30 ><DIV
31 CLASS="NAVHEADER"
32 ><TABLE
33 SUMMARY="Header navigation table"
34 WIDTH="100%"
35 BORDER="0"
36 CELLPADDING="0"
37 CELLSPACING="0"
38 ><TR
39 ><TH
40 COLSPAN="5"
41 ALIGN="center"
42 VALIGN="bottom"
43 >PostgreSQL 7.4.1 Documentation</TH
44 ></TR
45 ><TR
46 ><TD
47 WIDTH="10%"
48 ALIGN="left"
49 VALIGN="top"
50 ><A
51 HREF="xfunc-c.html"
52 ACCESSKEY="P"
53 >Prev</A
54 ></TD
55 ><TD
56 WIDTH="10%"
57 ALIGN="left"
58 VALIGN="top"
59 ><A
60 HREF="extend.html"
61 >Fast Backward</A
62 ></TD
63 ><TD
64 WIDTH="60%"
65 ALIGN="center"
66 VALIGN="bottom"
67 >Chapter 33. Extending <ACRONYM
68 CLASS="ACRONYM"
69 >SQL</ACRONYM
70 ></TD
71 ><TD
72 WIDTH="10%"
73 ALIGN="right"
74 VALIGN="top"
75 ><A
76 HREF="extend.html"
77 >Fast Forward</A
78 ></TD
79 ><TD
80 WIDTH="10%"
81 ALIGN="right"
82 VALIGN="top"
83 ><A
84 HREF="xaggr.html"
85 ACCESSKEY="N"
86 >Next</A
87 ></TD
88 ></TR
89 ></TABLE
90 ><HR
91 ALIGN="LEFT"
92 WIDTH="100%"></DIV
93 ><DIV
94 CLASS="SECT1"
95 ><H1
96 CLASS="SECT1"
97 ><A
98 NAME="XFUNC-OVERLOAD"
99 >33.8. Function Overloading</A
100 ></H1
101 ><A
102 NAME="AEN29709"
103 ></A
104 ><P
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
108 CLASS="FIRSTTERM"
109 >overloaded</I
110 >.  When a
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.
115    </P
116 ><P
117 >    A function may also have the same name as an attribute.  (Recall
118     that <TT
119 CLASS="LITERAL"
120 >attribute(table)</TT
121 > is equivalent to
122     <TT
123 CLASS="LITERAL"
124 >table.attribute</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.
128    </P
129 ><P
130 >    When creating a family of overloaded functions, one should be
131     careful not to create ambiguities.  For instance, given the
132     functions
133 </P><PRE
134 CLASS="PROGRAMLISTING"
135 >CREATE FUNCTION test(int, real) RETURNS ...
136 CREATE FUNCTION test(smallint, double precision) RETURNS ...</PRE
137 ><P>
138     it is not immediately clear which function would be called with
139     some trivial input like <TT
140 CLASS="LITERAL"
141 >test(1, 1.5)</TT
142 >.  The
143     currently implemented resolution rules are described in
144     <A
145 HREF="typeconv.html"
146 >Chapter 10</A
147 >, but it is unwise to design a system that subtly
148     relies on this behavior.
149    </P
150 ><P
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
158     <TT
159 CLASS="LITERAL"
160 >AS</TT
161 > clause for the SQL <TT
162 CLASS="COMMAND"
163 >CREATE
164     FUNCTION</TT
165 > command decouples the SQL function name from
166     the function name in the C source code.  E.g.,
167 </P><PRE
168 CLASS="PROGRAMLISTING"
169 >CREATE FUNCTION test(int) RETURNS int
170     AS '<VAR
171 CLASS="REPLACEABLE"
172 >filename</VAR
173 >', 'test_1arg'
174     LANGUAGE C;
175 CREATE FUNCTION test(int, int) RETURNS int
176     AS '<VAR
177 CLASS="REPLACEABLE"
178 >filename</VAR
179 >', 'test_2arg'
180     LANGUAGE C;</PRE
181 ><P>
182     The names of the C functions here reflect one of many possible conventions.
183    </P
184 ></DIV
185 ><DIV
186 CLASS="NAVFOOTER"
187 ><HR
188 ALIGN="LEFT"
189 WIDTH="100%"><TABLE
190 SUMMARY="Footer navigation table"
191 WIDTH="100%"
192 BORDER="0"
193 CELLPADDING="0"
194 CELLSPACING="0"
195 ><TR
196 ><TD
197 WIDTH="33%"
198 ALIGN="left"
199 VALIGN="top"
200 ><A
201 HREF="xfunc-c.html"
202 ACCESSKEY="P"
203 >Prev</A
204 ></TD
205 ><TD
206 WIDTH="34%"
207 ALIGN="center"
208 VALIGN="top"
209 ><A
210 HREF="index.html"
211 ACCESSKEY="H"
212 >Home</A
213 ></TD
214 ><TD
215 WIDTH="33%"
216 ALIGN="right"
217 VALIGN="top"
218 ><A
219 HREF="xaggr.html"
220 ACCESSKEY="N"
221 >Next</A
222 ></TD
223 ></TR
224 ><TR
225 ><TD
226 WIDTH="33%"
227 ALIGN="left"
228 VALIGN="top"
229 >C-Language Functions</TD
230 ><TD
231 WIDTH="34%"
232 ALIGN="center"
233 VALIGN="top"
234 ><A
235 HREF="extend.html"
236 ACCESSKEY="U"
237 >Up</A
238 ></TD
239 ><TD
240 WIDTH="33%"
241 ALIGN="right"
242 VALIGN="top"
243 >User-Defined Aggregates</TD
244 ></TR
245 ></TABLE
246 ></DIV
247 ></BODY
248 ></HTML
249 >