Properly access a buffer's LSN using existing access macros instead of abusing
[PostgreSQL.git] / src / backend / utils / adt / pseudotypes.c
bloba1145d1541d17b66c37224a93c5120a1320f063e
1 /*-------------------------------------------------------------------------
3 * pseudotypes.c
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
11 * we do better?)
14 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
15 * Portions Copyright (c) 1994, Regents of the University of California
18 * IDENTIFICATION
19 * $PostgreSQL$
21 *-------------------------------------------------------------------------
23 #include "postgres.h"
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')".
35 Datum
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.
49 Datum
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.
60 Datum
61 cstring_recv(PG_FUNCTION_ARGS)
63 StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
64 char *str;
65 int nbytes;
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.
74 Datum
75 cstring_send(PG_FUNCTION_ARGS)
77 char *str = PG_GETARG_CSTRING(0);
78 StringInfoData buf;
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.
89 Datum
90 any_in(PG_FUNCTION_ARGS)
92 ereport(ERROR,
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.
102 Datum
103 any_out(PG_FUNCTION_ARGS)
105 ereport(ERROR,
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.
116 Datum
117 anyarray_in(PG_FUNCTION_ARGS)
119 ereport(ERROR,
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.
131 Datum
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.
144 Datum
145 anyarray_recv(PG_FUNCTION_ARGS)
147 ereport(ERROR,
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.
159 Datum
160 anyarray_send(PG_FUNCTION_ARGS)
162 return array_send(fcinfo);
167 * anyenum_in - input routine for pseudo-type ANYENUM.
169 Datum
170 anyenum_in(PG_FUNCTION_ARGS)
172 ereport(ERROR,
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.
184 Datum
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.
198 Datum
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.
209 Datum
210 void_out(PG_FUNCTION_ARGS)
212 PG_RETURN_CSTRING(pstrdup(""));
217 * trigger_in - input routine for pseudo-type TRIGGER.
219 Datum
220 trigger_in(PG_FUNCTION_ARGS)
222 ereport(ERROR,
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.
232 Datum
233 trigger_out(PG_FUNCTION_ARGS)
235 ereport(ERROR,
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.
246 Datum
247 language_handler_in(PG_FUNCTION_ARGS)
249 ereport(ERROR,
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.
259 Datum
260 language_handler_out(PG_FUNCTION_ARGS)
262 ereport(ERROR,
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.
273 Datum
274 internal_in(PG_FUNCTION_ARGS)
276 ereport(ERROR,
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.
286 Datum
287 internal_out(PG_FUNCTION_ARGS)
289 ereport(ERROR,
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.
300 Datum
301 opaque_in(PG_FUNCTION_ARGS)
303 ereport(ERROR,
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.
313 Datum
314 opaque_out(PG_FUNCTION_ARGS)
316 ereport(ERROR,
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.
327 Datum
328 anyelement_in(PG_FUNCTION_ARGS)
330 ereport(ERROR,
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.
340 Datum
341 anyelement_out(PG_FUNCTION_ARGS)
343 ereport(ERROR,
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.
353 Datum
354 anynonarray_in(PG_FUNCTION_ARGS)
356 ereport(ERROR,
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.
366 Datum
367 anynonarray_out(PG_FUNCTION_ARGS)
369 ereport(ERROR,
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).
379 Datum
380 shell_in(PG_FUNCTION_ARGS)
382 ereport(ERROR,
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.
392 Datum
393 shell_out(PG_FUNCTION_ARGS)
395 ereport(ERROR,
396 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
397 errmsg("cannot display a value of a shell type")));
399 PG_RETURN_VOID(); /* keep compiler quiet */