]> granicus.if.org Git - postgresql/blob - src/backend/utils/adt/pseudotypes.c
Tag appropriate files for rc3
[postgresql] / src / backend / utils / adt / pseudotypes.c
1 /*-------------------------------------------------------------------------
2  *
3  * pseudotypes.c
4  *        Functions for the system pseudo-types.
5  *
6  * A pseudo-type isn't really a type and never has any operations, but
7  * we do need to supply input and output functions to satisfy the links
8  * in the pseudo-type's entry in pg_type.  In most cases the functions
9  * just throw an error if invoked.      (XXX the error messages here cover
10  * the most common case, but might be confusing in some contexts.  Can
11  * we do better?)
12  *
13  *
14  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
15  * Portions Copyright (c) 1994, Regents of the University of California
16  *
17  *
18  * IDENTIFICATION
19  *        $PostgreSQL: pgsql/src/backend/utils/adt/pseudotypes.c,v 1.15 2004/12/31 22:01:22 pgsql Exp $
20  *
21  *-------------------------------------------------------------------------
22  */
23 #include "postgres.h"
24
25 #include "libpq/pqformat.h"
26 #include "utils/array.h"
27 #include "utils/builtins.h"
28
29
30 /*
31  * cstring_in           - input routine for pseudo-type CSTRING.
32  *
33  * We might as well allow this to support constructs like "foo_in('blah')".
34  */
35 Datum
36 cstring_in(PG_FUNCTION_ARGS)
37 {
38         char       *str = PG_GETARG_CSTRING(0);
39
40         PG_RETURN_CSTRING(pstrdup(str));
41 }
42
43 /*
44  * cstring_out          - output routine for pseudo-type CSTRING.
45  *
46  * We allow this mainly so that "SELECT some_output_function(...)" does
47  * what the user will expect.
48  */
49 Datum
50 cstring_out(PG_FUNCTION_ARGS)
51 {
52         char       *str = PG_GETARG_CSTRING(0);
53
54         PG_RETURN_CSTRING(pstrdup(str));
55 }
56
57 /*
58  * cstring_recv         - binary input routine for pseudo-type CSTRING.
59  */
60 Datum
61 cstring_recv(PG_FUNCTION_ARGS)
62 {
63         StringInfo      buf = (StringInfo) PG_GETARG_POINTER(0);
64         char       *str;
65         int                     nbytes;
66
67         str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
68         PG_RETURN_CSTRING(str);
69 }
70
71 /*
72  * cstring_send         - binary output routine for pseudo-type CSTRING.
73  */
74 Datum
75 cstring_send(PG_FUNCTION_ARGS)
76 {
77         char       *str = PG_GETARG_CSTRING(0);
78         StringInfoData buf;
79
80         pq_begintypsend(&buf);
81         pq_sendtext(&buf, str, strlen(str));
82         PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
83 }
84
85
86 /*
87  * any_in               - input routine for pseudo-type ANY.
88  */
89 Datum
90 any_in(PG_FUNCTION_ARGS)
91 {
92         ereport(ERROR,
93                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
94                          errmsg("cannot accept a value of type any")));
95
96         PG_RETURN_VOID();                       /* keep compiler quiet */
97 }
98
99 /*
100  * any_out              - output routine for pseudo-type ANY.
101  */
102 Datum
103 any_out(PG_FUNCTION_ARGS)
104 {
105         ereport(ERROR,
106                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
107                          errmsg("cannot display a value of type any")));
108
109         PG_RETURN_VOID();                       /* keep compiler quiet */
110 }
111
112
113 /*
114  * anyarray_in          - input routine for pseudo-type ANYARRAY.
115  */
116 Datum
117 anyarray_in(PG_FUNCTION_ARGS)
118 {
119         ereport(ERROR,
120                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
121                          errmsg("cannot accept a value of type anyarray")));
122
123         PG_RETURN_VOID();                       /* keep compiler quiet */
124 }
125
126 /*
127  * anyarray_out         - output routine for pseudo-type ANYARRAY.
128  *
129  * We may as well allow this, since array_out will in fact work.
130  */
131 Datum
132 anyarray_out(PG_FUNCTION_ARGS)
133 {
134         return array_out(fcinfo);
135 }
136
137 /*
138  * anyarray_recv                - binary input routine for pseudo-type ANYARRAY.
139  *
140  * XXX this could actually be made to work, since the incoming array
141  * data will contain the element type OID.      Need to think through
142  * type-safety issues before allowing it, however.
143  */
144 Datum
145 anyarray_recv(PG_FUNCTION_ARGS)
146 {
147         ereport(ERROR,
148                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
149                          errmsg("cannot accept a value of type anyarray")));
150
151         PG_RETURN_VOID();                       /* keep compiler quiet */
152 }
153
154 /*
155  * anyarray_send                - binary output routine for pseudo-type ANYARRAY.
156  *
157  * We may as well allow this, since array_send will in fact work.
158  */
159 Datum
160 anyarray_send(PG_FUNCTION_ARGS)
161 {
162         return array_send(fcinfo);
163 }
164
165
166 /*
167  * void_in              - input routine for pseudo-type VOID.
168  *
169  * We allow this so that PL functions can return VOID without any special
170  * hack in the PL handler.      Whatever value the PL thinks it's returning
171  * will just be ignored.
172  */
173 Datum
174 void_in(PG_FUNCTION_ARGS)
175 {
176         PG_RETURN_VOID();                       /* you were expecting something different? */
177 }
178
179 /*
180  * void_out             - output routine for pseudo-type VOID.
181  *
182  * We allow this so that "SELECT function_returning_void(...)" works.
183  */
184 Datum
185 void_out(PG_FUNCTION_ARGS)
186 {
187         PG_RETURN_CSTRING(pstrdup(""));
188 }
189
190
191 /*
192  * trigger_in           - input routine for pseudo-type TRIGGER.
193  */
194 Datum
195 trigger_in(PG_FUNCTION_ARGS)
196 {
197         ereport(ERROR,
198                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
199                          errmsg("cannot accept a value of type trigger")));
200
201         PG_RETURN_VOID();                       /* keep compiler quiet */
202 }
203
204 /*
205  * trigger_out          - output routine for pseudo-type TRIGGER.
206  */
207 Datum
208 trigger_out(PG_FUNCTION_ARGS)
209 {
210         ereport(ERROR,
211                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
212                          errmsg("cannot display a value of type trigger")));
213
214         PG_RETURN_VOID();                       /* keep compiler quiet */
215 }
216
217
218 /*
219  * language_handler_in          - input routine for pseudo-type LANGUAGE_HANDLER.
220  */
221 Datum
222 language_handler_in(PG_FUNCTION_ARGS)
223 {
224         ereport(ERROR,
225                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
226                          errmsg("cannot accept a value of type language_handler")));
227
228         PG_RETURN_VOID();                       /* keep compiler quiet */
229 }
230
231 /*
232  * language_handler_out         - output routine for pseudo-type LANGUAGE_HANDLER.
233  */
234 Datum
235 language_handler_out(PG_FUNCTION_ARGS)
236 {
237         ereport(ERROR,
238                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
239                          errmsg("cannot display a value of type language_handler")));
240
241         PG_RETURN_VOID();                       /* keep compiler quiet */
242 }
243
244
245 /*
246  * internal_in          - input routine for pseudo-type INTERNAL.
247  */
248 Datum
249 internal_in(PG_FUNCTION_ARGS)
250 {
251         ereport(ERROR,
252                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
253                          errmsg("cannot accept a value of type internal")));
254
255         PG_RETURN_VOID();                       /* keep compiler quiet */
256 }
257
258 /*
259  * internal_out         - output routine for pseudo-type INTERNAL.
260  */
261 Datum
262 internal_out(PG_FUNCTION_ARGS)
263 {
264         ereport(ERROR,
265                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
266                          errmsg("cannot display a value of type internal")));
267
268         PG_RETURN_VOID();                       /* keep compiler quiet */
269 }
270
271
272 /*
273  * opaque_in            - input routine for pseudo-type OPAQUE.
274  */
275 Datum
276 opaque_in(PG_FUNCTION_ARGS)
277 {
278         ereport(ERROR,
279                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
280                          errmsg("cannot accept a value of type opaque")));
281
282         PG_RETURN_VOID();                       /* keep compiler quiet */
283 }
284
285 /*
286  * opaque_out           - output routine for pseudo-type OPAQUE.
287  */
288 Datum
289 opaque_out(PG_FUNCTION_ARGS)
290 {
291         ereport(ERROR,
292                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
293                          errmsg("cannot display a value of type opaque")));
294
295         PG_RETURN_VOID();                       /* keep compiler quiet */
296 }
297
298
299 /*
300  * anyelement_in                - input routine for pseudo-type ANYELEMENT.
301  */
302 Datum
303 anyelement_in(PG_FUNCTION_ARGS)
304 {
305         ereport(ERROR,
306                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
307                          errmsg("cannot accept a value of type anyelement")));
308
309         PG_RETURN_VOID();                       /* keep compiler quiet */
310 }
311
312 /*
313  * anyelement_out               - output routine for pseudo-type ANYELEMENT.
314  */
315 Datum
316 anyelement_out(PG_FUNCTION_ARGS)
317 {
318         ereport(ERROR,
319                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
320                          errmsg("cannot display a value of type anyelement")));
321
322         PG_RETURN_VOID();                       /* keep compiler quiet */
323 }