1 /*-------------------------------------------------------------------------
4 * Functions for the system pseudo-types.
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
14 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
15 * Portions Copyright (c) 1994, Regents of the University of California
21 *-------------------------------------------------------------------------
25 #include "libpq/pqformat.h"
26 #include "utils/array.h"
27 #include "utils/builtins.h"
31 * cstring_in - input routine for pseudo-type CSTRING.
33 * We might as well allow this to support constructs like "foo_in('blah')".
36 cstring_in(PG_FUNCTION_ARGS
)
38 char *str
= PG_GETARG_CSTRING(0);
40 PG_RETURN_CSTRING(pstrdup(str
));
44 * cstring_out - output routine for pseudo-type CSTRING.
46 * We allow this mainly so that "SELECT some_output_function(...)" does
47 * what the user will expect.
50 cstring_out(PG_FUNCTION_ARGS
)
52 char *str
= PG_GETARG_CSTRING(0);
54 PG_RETURN_CSTRING(pstrdup(str
));
58 * cstring_recv - binary input routine for pseudo-type CSTRING.
61 cstring_recv(PG_FUNCTION_ARGS
)
63 StringInfo buf
= (StringInfo
) PG_GETARG_POINTER(0);
67 str
= pq_getmsgtext(buf
, buf
->len
- buf
->cursor
, &nbytes
);
68 PG_RETURN_CSTRING(str
);
72 * cstring_send - binary output routine for pseudo-type CSTRING.
75 cstring_send(PG_FUNCTION_ARGS
)
77 char *str
= PG_GETARG_CSTRING(0);
80 pq_begintypsend(&buf
);
81 pq_sendtext(&buf
, str
, strlen(str
));
82 PG_RETURN_BYTEA_P(pq_endtypsend(&buf
));
87 * any_in - input routine for pseudo-type ANY.
90 any_in(PG_FUNCTION_ARGS
)
93 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED
),
94 errmsg("cannot accept a value of type any")));
96 PG_RETURN_VOID(); /* keep compiler quiet */
100 * any_out - output routine for pseudo-type ANY.
103 any_out(PG_FUNCTION_ARGS
)
106 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED
),
107 errmsg("cannot display a value of type any")));
109 PG_RETURN_VOID(); /* keep compiler quiet */
114 * anyarray_in - input routine for pseudo-type ANYARRAY.
117 anyarray_in(PG_FUNCTION_ARGS
)
120 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED
),
121 errmsg("cannot accept a value of type anyarray")));
123 PG_RETURN_VOID(); /* keep compiler quiet */
127 * anyarray_out - output routine for pseudo-type ANYARRAY.
129 * We may as well allow this, since array_out will in fact work.
132 anyarray_out(PG_FUNCTION_ARGS
)
134 return array_out(fcinfo
);
138 * anyarray_recv - binary input routine for pseudo-type ANYARRAY.
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.
145 anyarray_recv(PG_FUNCTION_ARGS
)
148 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED
),
149 errmsg("cannot accept a value of type anyarray")));
151 PG_RETURN_VOID(); /* keep compiler quiet */
155 * anyarray_send - binary output routine for pseudo-type ANYARRAY.
157 * We may as well allow this, since array_send will in fact work.
160 anyarray_send(PG_FUNCTION_ARGS
)
162 return array_send(fcinfo
);
167 * anyenum_in - input routine for pseudo-type ANYENUM.
170 anyenum_in(PG_FUNCTION_ARGS
)
173 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED
),
174 errmsg("cannot accept a value of type anyenum")));
176 PG_RETURN_VOID(); /* keep compiler quiet */
180 * anyenum_out - output routine for pseudo-type ANYENUM.
182 * We may as well allow this, since enum_out will in fact work.
185 anyenum_out(PG_FUNCTION_ARGS
)
187 return enum_out(fcinfo
);
192 * void_in - input routine for pseudo-type VOID.
194 * We allow this so that PL functions can return VOID without any special
195 * hack in the PL handler. Whatever value the PL thinks it's returning
196 * will just be ignored.
199 void_in(PG_FUNCTION_ARGS
)
201 PG_RETURN_VOID(); /* you were expecting something different? */
205 * void_out - output routine for pseudo-type VOID.
207 * We allow this so that "SELECT function_returning_void(...)" works.
210 void_out(PG_FUNCTION_ARGS
)
212 PG_RETURN_CSTRING(pstrdup(""));
217 * trigger_in - input routine for pseudo-type TRIGGER.
220 trigger_in(PG_FUNCTION_ARGS
)
223 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED
),
224 errmsg("cannot accept a value of type trigger")));
226 PG_RETURN_VOID(); /* keep compiler quiet */
230 * trigger_out - output routine for pseudo-type TRIGGER.
233 trigger_out(PG_FUNCTION_ARGS
)
236 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED
),
237 errmsg("cannot display a value of type trigger")));
239 PG_RETURN_VOID(); /* keep compiler quiet */
244 * language_handler_in - input routine for pseudo-type LANGUAGE_HANDLER.
247 language_handler_in(PG_FUNCTION_ARGS
)
250 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED
),
251 errmsg("cannot accept a value of type language_handler")));
253 PG_RETURN_VOID(); /* keep compiler quiet */
257 * language_handler_out - output routine for pseudo-type LANGUAGE_HANDLER.
260 language_handler_out(PG_FUNCTION_ARGS
)
263 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED
),
264 errmsg("cannot display a value of type language_handler")));
266 PG_RETURN_VOID(); /* keep compiler quiet */
271 * internal_in - input routine for pseudo-type INTERNAL.
274 internal_in(PG_FUNCTION_ARGS
)
277 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED
),
278 errmsg("cannot accept a value of type internal")));
280 PG_RETURN_VOID(); /* keep compiler quiet */
284 * internal_out - output routine for pseudo-type INTERNAL.
287 internal_out(PG_FUNCTION_ARGS
)
290 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED
),
291 errmsg("cannot display a value of type internal")));
293 PG_RETURN_VOID(); /* keep compiler quiet */
298 * opaque_in - input routine for pseudo-type OPAQUE.
301 opaque_in(PG_FUNCTION_ARGS
)
304 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED
),
305 errmsg("cannot accept a value of type opaque")));
307 PG_RETURN_VOID(); /* keep compiler quiet */
311 * opaque_out - output routine for pseudo-type OPAQUE.
314 opaque_out(PG_FUNCTION_ARGS
)
317 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED
),
318 errmsg("cannot display a value of type opaque")));
320 PG_RETURN_VOID(); /* keep compiler quiet */
325 * anyelement_in - input routine for pseudo-type ANYELEMENT.
328 anyelement_in(PG_FUNCTION_ARGS
)
331 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED
),
332 errmsg("cannot accept a value of type anyelement")));
334 PG_RETURN_VOID(); /* keep compiler quiet */
338 * anyelement_out - output routine for pseudo-type ANYELEMENT.
341 anyelement_out(PG_FUNCTION_ARGS
)
344 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED
),
345 errmsg("cannot display a value of type anyelement")));
347 PG_RETURN_VOID(); /* keep compiler quiet */
351 * anynonarray_in - input routine for pseudo-type ANYNONARRAY.
354 anynonarray_in(PG_FUNCTION_ARGS
)
357 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED
),
358 errmsg("cannot accept a value of type anynonarray")));
360 PG_RETURN_VOID(); /* keep compiler quiet */
364 * anynonarray_out - output routine for pseudo-type ANYNONARRAY.
367 anynonarray_out(PG_FUNCTION_ARGS
)
370 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED
),
371 errmsg("cannot display a value of type anynonarray")));
373 PG_RETURN_VOID(); /* keep compiler quiet */
377 * shell_in - input routine for "shell" types (those not yet filled in).
380 shell_in(PG_FUNCTION_ARGS
)
383 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED
),
384 errmsg("cannot accept a value of a shell type")));
386 PG_RETURN_VOID(); /* keep compiler quiet */
390 * shell_out - output routine for "shell" types.
393 shell_out(PG_FUNCTION_ARGS
)
396 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED
),
397 errmsg("cannot display a value of a shell type")));
399 PG_RETURN_VOID(); /* keep compiler quiet */