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-2013, PostgreSQL Global Development Group
15 * Portions Copyright (c) 1994, Regents of the University of California
19 * src/backend/utils/adt/pseudotypes.c
21 *-------------------------------------------------------------------------
25 #include "libpq/pqformat.h"
26 #include "utils/array.h"
27 #include "utils/builtins.h"
28 #include "utils/rangetypes.h"
32 * cstring_in - input routine for pseudo-type CSTRING.
34 * We might as well allow this to support constructs like "foo_in('blah')".
37 cstring_in(PG_FUNCTION_ARGS)
39 char *str = PG_GETARG_CSTRING(0);
41 PG_RETURN_CSTRING(pstrdup(str));
45 * cstring_out - output routine for pseudo-type CSTRING.
47 * We allow this mainly so that "SELECT some_output_function(...)" does
48 * what the user will expect.
51 cstring_out(PG_FUNCTION_ARGS)
53 char *str = PG_GETARG_CSTRING(0);
55 PG_RETURN_CSTRING(pstrdup(str));
59 * cstring_recv - binary input routine for pseudo-type CSTRING.
62 cstring_recv(PG_FUNCTION_ARGS)
64 StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
68 str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
69 PG_RETURN_CSTRING(str);
73 * cstring_send - binary output routine for pseudo-type CSTRING.
76 cstring_send(PG_FUNCTION_ARGS)
78 char *str = PG_GETARG_CSTRING(0);
81 pq_begintypsend(&buf);
82 pq_sendtext(&buf, str, strlen(str));
83 PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
88 * any_in - input routine for pseudo-type ANY.
91 any_in(PG_FUNCTION_ARGS)
94 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
95 errmsg("cannot accept a value of type any")));
97 PG_RETURN_VOID(); /* keep compiler quiet */
101 * any_out - output routine for pseudo-type ANY.
104 any_out(PG_FUNCTION_ARGS)
107 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
108 errmsg("cannot display a value of type any")));
110 PG_RETURN_VOID(); /* keep compiler quiet */
115 * anyarray_in - input routine for pseudo-type ANYARRAY.
118 anyarray_in(PG_FUNCTION_ARGS)
121 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
122 errmsg("cannot accept a value of type anyarray")));
124 PG_RETURN_VOID(); /* keep compiler quiet */
128 * anyarray_out - output routine for pseudo-type ANYARRAY.
130 * We may as well allow this, since array_out will in fact work.
133 anyarray_out(PG_FUNCTION_ARGS)
135 return array_out(fcinfo);
139 * anyarray_recv - binary input routine for pseudo-type ANYARRAY.
141 * XXX this could actually be made to work, since the incoming array
142 * data will contain the element type OID. Need to think through
143 * type-safety issues before allowing it, however.
146 anyarray_recv(PG_FUNCTION_ARGS)
149 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
150 errmsg("cannot accept a value of type anyarray")));
152 PG_RETURN_VOID(); /* keep compiler quiet */
156 * anyarray_send - binary output routine for pseudo-type ANYARRAY.
158 * We may as well allow this, since array_send will in fact work.
161 anyarray_send(PG_FUNCTION_ARGS)
163 return array_send(fcinfo);
168 * anyenum_in - input routine for pseudo-type ANYENUM.
171 anyenum_in(PG_FUNCTION_ARGS)
174 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
175 errmsg("cannot accept a value of type anyenum")));
177 PG_RETURN_VOID(); /* keep compiler quiet */
181 * anyenum_out - output routine for pseudo-type ANYENUM.
183 * We may as well allow this, since enum_out will in fact work.
186 anyenum_out(PG_FUNCTION_ARGS)
188 return enum_out(fcinfo);
192 * anyrange_in - input routine for pseudo-type ANYRANGE.
195 anyrange_in(PG_FUNCTION_ARGS)
198 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
199 errmsg("cannot accept a value of type anyrange")));
201 PG_RETURN_VOID(); /* keep compiler quiet */
205 * anyrange_out - output routine for pseudo-type ANYRANGE.
207 * We may as well allow this, since range_out will in fact work.
210 anyrange_out(PG_FUNCTION_ARGS)
212 return range_out(fcinfo);
216 * void_in - input routine for pseudo-type VOID.
218 * We allow this so that PL functions can return VOID without any special
219 * hack in the PL handler. Whatever value the PL thinks it's returning
220 * will just be ignored.
223 void_in(PG_FUNCTION_ARGS)
225 PG_RETURN_VOID(); /* you were expecting something different? */
229 * void_out - output routine for pseudo-type VOID.
231 * We allow this so that "SELECT function_returning_void(...)" works.
234 void_out(PG_FUNCTION_ARGS)
236 PG_RETURN_CSTRING(pstrdup(""));
240 * void_recv - binary input routine for pseudo-type VOID.
242 * Note that since we consume no bytes, an attempt to send anything but
243 * an empty string will result in an "invalid message format" error.
246 void_recv(PG_FUNCTION_ARGS)
252 * void_send - binary output routine for pseudo-type VOID.
254 * We allow this so that "SELECT function_returning_void(...)" works
255 * even when binary output is requested.
258 void_send(PG_FUNCTION_ARGS)
262 /* send an empty string */
263 pq_begintypsend(&buf);
264 PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
269 * trigger_in - input routine for pseudo-type TRIGGER.
272 trigger_in(PG_FUNCTION_ARGS)
275 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
276 errmsg("cannot accept a value of type trigger")));
278 PG_RETURN_VOID(); /* keep compiler quiet */
282 * trigger_out - output routine for pseudo-type TRIGGER.
285 trigger_out(PG_FUNCTION_ARGS)
288 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
289 errmsg("cannot display a value of type trigger")));
291 PG_RETURN_VOID(); /* keep compiler quiet */
296 * event_trigger_in - input routine for pseudo-type event_trigger.
299 event_trigger_in(PG_FUNCTION_ARGS)
302 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
303 errmsg("cannot accept a value of type event_trigger")));
305 PG_RETURN_VOID(); /* keep compiler quiet */
309 * event_trigger_out - output routine for pseudo-type event_trigger.
312 event_trigger_out(PG_FUNCTION_ARGS)
315 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
316 errmsg("cannot display a value of type event_trigger")));
318 PG_RETURN_VOID(); /* keep compiler quiet */
323 * language_handler_in - input routine for pseudo-type LANGUAGE_HANDLER.
326 language_handler_in(PG_FUNCTION_ARGS)
329 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
330 errmsg("cannot accept a value of type language_handler")));
332 PG_RETURN_VOID(); /* keep compiler quiet */
336 * language_handler_out - output routine for pseudo-type LANGUAGE_HANDLER.
339 language_handler_out(PG_FUNCTION_ARGS)
342 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
343 errmsg("cannot display a value of type language_handler")));
345 PG_RETURN_VOID(); /* keep compiler quiet */
350 * fdw_handler_in - input routine for pseudo-type FDW_HANDLER.
353 fdw_handler_in(PG_FUNCTION_ARGS)
356 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
357 errmsg("cannot accept a value of type fdw_handler")));
359 PG_RETURN_VOID(); /* keep compiler quiet */
363 * fdw_handler_out - output routine for pseudo-type FDW_HANDLER.
366 fdw_handler_out(PG_FUNCTION_ARGS)
369 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
370 errmsg("cannot display a value of type fdw_handler")));
372 PG_RETURN_VOID(); /* keep compiler quiet */
377 * internal_in - input routine for pseudo-type INTERNAL.
380 internal_in(PG_FUNCTION_ARGS)
383 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
384 errmsg("cannot accept a value of type internal")));
386 PG_RETURN_VOID(); /* keep compiler quiet */
390 * internal_out - output routine for pseudo-type INTERNAL.
393 internal_out(PG_FUNCTION_ARGS)
396 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
397 errmsg("cannot display a value of type internal")));
399 PG_RETURN_VOID(); /* keep compiler quiet */
404 * opaque_in - input routine for pseudo-type OPAQUE.
407 opaque_in(PG_FUNCTION_ARGS)
410 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
411 errmsg("cannot accept a value of type opaque")));
413 PG_RETURN_VOID(); /* keep compiler quiet */
417 * opaque_out - output routine for pseudo-type OPAQUE.
420 opaque_out(PG_FUNCTION_ARGS)
423 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
424 errmsg("cannot display a value of type opaque")));
426 PG_RETURN_VOID(); /* keep compiler quiet */
431 * anyelement_in - input routine for pseudo-type ANYELEMENT.
434 anyelement_in(PG_FUNCTION_ARGS)
437 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
438 errmsg("cannot accept a value of type anyelement")));
440 PG_RETURN_VOID(); /* keep compiler quiet */
444 * anyelement_out - output routine for pseudo-type ANYELEMENT.
447 anyelement_out(PG_FUNCTION_ARGS)
450 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
451 errmsg("cannot display a value of type anyelement")));
453 PG_RETURN_VOID(); /* keep compiler quiet */
457 * anynonarray_in - input routine for pseudo-type ANYNONARRAY.
460 anynonarray_in(PG_FUNCTION_ARGS)
463 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
464 errmsg("cannot accept a value of type anynonarray")));
466 PG_RETURN_VOID(); /* keep compiler quiet */
470 * anynonarray_out - output routine for pseudo-type ANYNONARRAY.
473 anynonarray_out(PG_FUNCTION_ARGS)
476 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
477 errmsg("cannot display a value of type anynonarray")));
479 PG_RETURN_VOID(); /* keep compiler quiet */
483 * shell_in - input routine for "shell" types (those not yet filled in).
486 shell_in(PG_FUNCTION_ARGS)
489 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
490 errmsg("cannot accept a value of a shell type")));
492 PG_RETURN_VOID(); /* keep compiler quiet */
496 * shell_out - output routine for "shell" types.
499 shell_out(PG_FUNCTION_ARGS)
502 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
503 errmsg("cannot display a value of a shell type")));
505 PG_RETURN_VOID(); /* keep compiler quiet */
510 * pg_node_tree_in - input routine for type PG_NODE_TREE.
512 * pg_node_tree isn't really a pseudotype --- it's real enough to be a table
513 * column --- but it presently has no operations of its own, and disallows
514 * input too, so its I/O functions seem to fit here as much as anywhere.
517 pg_node_tree_in(PG_FUNCTION_ARGS)
520 * We disallow input of pg_node_tree values because the SQL functions that
521 * operate on the type are not secure against malformed input.
524 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
525 errmsg("cannot accept a value of type pg_node_tree")));
527 PG_RETURN_VOID(); /* keep compiler quiet */
531 * pg_node_tree_out - output routine for type PG_NODE_TREE.
533 * The internal representation is the same as TEXT, so just pass it off.
536 pg_node_tree_out(PG_FUNCTION_ARGS)
538 return textout(fcinfo);
542 * pg_node_tree_recv - binary input routine for type PG_NODE_TREE.
545 pg_node_tree_recv(PG_FUNCTION_ARGS)
548 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
549 errmsg("cannot accept a value of type pg_node_tree")));
551 PG_RETURN_VOID(); /* keep compiler quiet */
555 * pg_node_tree_send - binary output routine for type PG_NODE_TREE.
558 pg_node_tree_send(PG_FUNCTION_ARGS)
560 return textsend(fcinfo);