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-2003, PostgreSQL Global Development Group
15 * Portions Copyright (c) 1994, Regents of the University of California
19 * $PostgreSQL: pgsql/src/backend/utils/adt/pseudotypes.c,v 1.13 2004/04/01 21:28:45 tgl Exp $
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 * void_in - input routine for pseudo-type VOID.
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.
174 void_in(PG_FUNCTION_ARGS)
176 PG_RETURN_VOID(); /* you were expecting something different? */
180 * void_out - output routine for pseudo-type VOID.
182 * We allow this so that "SELECT function_returning_void(...)" works.
185 void_out(PG_FUNCTION_ARGS)
187 PG_RETURN_CSTRING(pstrdup(""));
192 * trigger_in - input routine for pseudo-type TRIGGER.
195 trigger_in(PG_FUNCTION_ARGS)
198 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
199 errmsg("cannot accept a value of type trigger")));
201 PG_RETURN_VOID(); /* keep compiler quiet */
205 * trigger_out - output routine for pseudo-type TRIGGER.
208 trigger_out(PG_FUNCTION_ARGS)
211 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
212 errmsg("cannot display a value of type trigger")));
214 PG_RETURN_VOID(); /* keep compiler quiet */
219 * language_handler_in - input routine for pseudo-type LANGUAGE_HANDLER.
222 language_handler_in(PG_FUNCTION_ARGS)
225 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
226 errmsg("cannot accept a value of type language_handler")));
228 PG_RETURN_VOID(); /* keep compiler quiet */
232 * language_handler_out - output routine for pseudo-type LANGUAGE_HANDLER.
235 language_handler_out(PG_FUNCTION_ARGS)
238 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
239 errmsg("cannot display a value of type language_handler")));
241 PG_RETURN_VOID(); /* keep compiler quiet */
246 * internal_in - input routine for pseudo-type INTERNAL.
249 internal_in(PG_FUNCTION_ARGS)
252 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
253 errmsg("cannot accept a value of type internal")));
255 PG_RETURN_VOID(); /* keep compiler quiet */
259 * internal_out - output routine for pseudo-type INTERNAL.
262 internal_out(PG_FUNCTION_ARGS)
265 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
266 errmsg("cannot display a value of type internal")));
268 PG_RETURN_VOID(); /* keep compiler quiet */
273 * opaque_in - input routine for pseudo-type OPAQUE.
276 opaque_in(PG_FUNCTION_ARGS)
279 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
280 errmsg("cannot accept a value of type opaque")));
282 PG_RETURN_VOID(); /* keep compiler quiet */
286 * opaque_out - output routine for pseudo-type OPAQUE.
289 opaque_out(PG_FUNCTION_ARGS)
292 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
293 errmsg("cannot display a value of type opaque")));
295 PG_RETURN_VOID(); /* keep compiler quiet */
300 * anyelement_in - input routine for pseudo-type ANYELEMENT.
303 anyelement_in(PG_FUNCTION_ARGS)
306 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
307 errmsg("cannot accept a value of type anyelement")));
309 PG_RETURN_VOID(); /* keep compiler quiet */
313 * anyelement_out - output routine for pseudo-type ANYELEMENT.
316 anyelement_out(PG_FUNCTION_ARGS)
319 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
320 errmsg("cannot display a value of type anyelement")));
322 PG_RETURN_VOID(); /* keep compiler quiet */