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-2011, 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"
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(""));
216
* void_recv - binary input routine for pseudo-type VOID.
218
* Note that since we consume no bytes, an attempt to send anything but
219
* an empty string will result in an "invalid message format" error.
222
void_recv(PG_FUNCTION_ARGS)
228
* void_send - binary output routine for pseudo-type VOID.
230
* We allow this so that "SELECT function_returning_void(...)" works
231
* even when binary output is requested.
234
void_send(PG_FUNCTION_ARGS)
238
/* send an empty string */
239
pq_begintypsend(&buf);
240
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
245
* trigger_in - input routine for pseudo-type TRIGGER.
248
trigger_in(PG_FUNCTION_ARGS)
251
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
252
errmsg("cannot accept a value of type trigger")));
254
PG_RETURN_VOID(); /* keep compiler quiet */
258
* trigger_out - output routine for pseudo-type TRIGGER.
261
trigger_out(PG_FUNCTION_ARGS)
264
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
265
errmsg("cannot display a value of type trigger")));
267
PG_RETURN_VOID(); /* keep compiler quiet */
272
* language_handler_in - input routine for pseudo-type LANGUAGE_HANDLER.
275
language_handler_in(PG_FUNCTION_ARGS)
278
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
279
errmsg("cannot accept a value of type language_handler")));
281
PG_RETURN_VOID(); /* keep compiler quiet */
285
* language_handler_out - output routine for pseudo-type LANGUAGE_HANDLER.
288
language_handler_out(PG_FUNCTION_ARGS)
291
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
292
errmsg("cannot display a value of type language_handler")));
294
PG_RETURN_VOID(); /* keep compiler quiet */
299
* fdw_handler_in - input routine for pseudo-type FDW_HANDLER.
302
fdw_handler_in(PG_FUNCTION_ARGS)
305
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
306
errmsg("cannot accept a value of type fdw_handler")));
308
PG_RETURN_VOID(); /* keep compiler quiet */
312
* fdw_handler_out - output routine for pseudo-type FDW_HANDLER.
315
fdw_handler_out(PG_FUNCTION_ARGS)
318
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
319
errmsg("cannot display a value of type fdw_handler")));
321
PG_RETURN_VOID(); /* keep compiler quiet */
326
* internal_in - input routine for pseudo-type INTERNAL.
329
internal_in(PG_FUNCTION_ARGS)
332
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
333
errmsg("cannot accept a value of type internal")));
335
PG_RETURN_VOID(); /* keep compiler quiet */
339
* internal_out - output routine for pseudo-type INTERNAL.
342
internal_out(PG_FUNCTION_ARGS)
345
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
346
errmsg("cannot display a value of type internal")));
348
PG_RETURN_VOID(); /* keep compiler quiet */
353
* opaque_in - input routine for pseudo-type OPAQUE.
356
opaque_in(PG_FUNCTION_ARGS)
359
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
360
errmsg("cannot accept a value of type opaque")));
362
PG_RETURN_VOID(); /* keep compiler quiet */
366
* opaque_out - output routine for pseudo-type OPAQUE.
369
opaque_out(PG_FUNCTION_ARGS)
372
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
373
errmsg("cannot display a value of type opaque")));
375
PG_RETURN_VOID(); /* keep compiler quiet */
380
* anyelement_in - input routine for pseudo-type ANYELEMENT.
383
anyelement_in(PG_FUNCTION_ARGS)
386
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
387
errmsg("cannot accept a value of type anyelement")));
389
PG_RETURN_VOID(); /* keep compiler quiet */
393
* anyelement_out - output routine for pseudo-type ANYELEMENT.
396
anyelement_out(PG_FUNCTION_ARGS)
399
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
400
errmsg("cannot display a value of type anyelement")));
402
PG_RETURN_VOID(); /* keep compiler quiet */
406
* anynonarray_in - input routine for pseudo-type ANYNONARRAY.
409
anynonarray_in(PG_FUNCTION_ARGS)
412
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
413
errmsg("cannot accept a value of type anynonarray")));
415
PG_RETURN_VOID(); /* keep compiler quiet */
419
* anynonarray_out - output routine for pseudo-type ANYNONARRAY.
422
anynonarray_out(PG_FUNCTION_ARGS)
425
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
426
errmsg("cannot display a value of type anynonarray")));
428
PG_RETURN_VOID(); /* keep compiler quiet */
432
* shell_in - input routine for "shell" types (those not yet filled in).
435
shell_in(PG_FUNCTION_ARGS)
438
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
439
errmsg("cannot accept a value of a shell type")));
441
PG_RETURN_VOID(); /* keep compiler quiet */
445
* shell_out - output routine for "shell" types.
448
shell_out(PG_FUNCTION_ARGS)
451
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
452
errmsg("cannot display a value of a shell type")));
454
PG_RETURN_VOID(); /* keep compiler quiet */
459
* pg_node_tree_in - input routine for type PG_NODE_TREE.
461
* pg_node_tree isn't really a pseudotype --- it's real enough to be a table
462
* column --- but it presently has no operations of its own, and disallows
463
* input too, so its I/O functions seem to fit here as much as anywhere.
466
pg_node_tree_in(PG_FUNCTION_ARGS)
469
* We disallow input of pg_node_tree values because the SQL functions that
470
* operate on the type are not secure against malformed input.
473
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
474
errmsg("cannot accept a value of type pg_node_tree")));
476
PG_RETURN_VOID(); /* keep compiler quiet */
480
* pg_node_tree_out - output routine for type PG_NODE_TREE.
482
* The internal representation is the same as TEXT, so just pass it off.
485
pg_node_tree_out(PG_FUNCTION_ARGS)
487
return textout(fcinfo);
491
* pg_node_tree_recv - binary input routine for type PG_NODE_TREE.
494
pg_node_tree_recv(PG_FUNCTION_ARGS)
497
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
498
errmsg("cannot accept a value of type pg_node_tree")));
500
PG_RETURN_VOID(); /* keep compiler quiet */
504
* pg_node_tree_send - binary output routine for type PG_NODE_TREE.
507
pg_node_tree_send(PG_FUNCTION_ARGS)
509
return textsend(fcinfo);