Header And Logo

PostgreSQL
| The world's most advanced open source database.

pseudotypes.c

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * pseudotypes.c
00004  *    Functions for the system pseudo-types.
00005  *
00006  * A pseudo-type isn't really a type and never has any operations, but
00007  * we do need to supply input and output functions to satisfy the links
00008  * in the pseudo-type's entry in pg_type.  In most cases the functions
00009  * just throw an error if invoked.  (XXX the error messages here cover
00010  * the most common case, but might be confusing in some contexts.  Can
00011  * we do better?)
00012  *
00013  *
00014  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00015  * Portions Copyright (c) 1994, Regents of the University of California
00016  *
00017  *
00018  * IDENTIFICATION
00019  *    src/backend/utils/adt/pseudotypes.c
00020  *
00021  *-------------------------------------------------------------------------
00022  */
00023 #include "postgres.h"
00024 
00025 #include "libpq/pqformat.h"
00026 #include "utils/array.h"
00027 #include "utils/builtins.h"
00028 #include "utils/rangetypes.h"
00029 
00030 
00031 /*
00032  * cstring_in       - input routine for pseudo-type CSTRING.
00033  *
00034  * We might as well allow this to support constructs like "foo_in('blah')".
00035  */
00036 Datum
00037 cstring_in(PG_FUNCTION_ARGS)
00038 {
00039     char       *str = PG_GETARG_CSTRING(0);
00040 
00041     PG_RETURN_CSTRING(pstrdup(str));
00042 }
00043 
00044 /*
00045  * cstring_out      - output routine for pseudo-type CSTRING.
00046  *
00047  * We allow this mainly so that "SELECT some_output_function(...)" does
00048  * what the user will expect.
00049  */
00050 Datum
00051 cstring_out(PG_FUNCTION_ARGS)
00052 {
00053     char       *str = PG_GETARG_CSTRING(0);
00054 
00055     PG_RETURN_CSTRING(pstrdup(str));
00056 }
00057 
00058 /*
00059  * cstring_recv     - binary input routine for pseudo-type CSTRING.
00060  */
00061 Datum
00062 cstring_recv(PG_FUNCTION_ARGS)
00063 {
00064     StringInfo  buf = (StringInfo) PG_GETARG_POINTER(0);
00065     char       *str;
00066     int         nbytes;
00067 
00068     str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
00069     PG_RETURN_CSTRING(str);
00070 }
00071 
00072 /*
00073  * cstring_send     - binary output routine for pseudo-type CSTRING.
00074  */
00075 Datum
00076 cstring_send(PG_FUNCTION_ARGS)
00077 {
00078     char       *str = PG_GETARG_CSTRING(0);
00079     StringInfoData buf;
00080 
00081     pq_begintypsend(&buf);
00082     pq_sendtext(&buf, str, strlen(str));
00083     PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
00084 }
00085 
00086 
00087 /*
00088  * any_in       - input routine for pseudo-type ANY.
00089  */
00090 Datum
00091 any_in(PG_FUNCTION_ARGS)
00092 {
00093     ereport(ERROR,
00094             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00095              errmsg("cannot accept a value of type any")));
00096 
00097     PG_RETURN_VOID();           /* keep compiler quiet */
00098 }
00099 
00100 /*
00101  * any_out      - output routine for pseudo-type ANY.
00102  */
00103 Datum
00104 any_out(PG_FUNCTION_ARGS)
00105 {
00106     ereport(ERROR,
00107             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00108              errmsg("cannot display a value of type any")));
00109 
00110     PG_RETURN_VOID();           /* keep compiler quiet */
00111 }
00112 
00113 
00114 /*
00115  * anyarray_in      - input routine for pseudo-type ANYARRAY.
00116  */
00117 Datum
00118 anyarray_in(PG_FUNCTION_ARGS)
00119 {
00120     ereport(ERROR,
00121             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00122              errmsg("cannot accept a value of type anyarray")));
00123 
00124     PG_RETURN_VOID();           /* keep compiler quiet */
00125 }
00126 
00127 /*
00128  * anyarray_out     - output routine for pseudo-type ANYARRAY.
00129  *
00130  * We may as well allow this, since array_out will in fact work.
00131  */
00132 Datum
00133 anyarray_out(PG_FUNCTION_ARGS)
00134 {
00135     return array_out(fcinfo);
00136 }
00137 
00138 /*
00139  * anyarray_recv        - binary input routine for pseudo-type ANYARRAY.
00140  *
00141  * XXX this could actually be made to work, since the incoming array
00142  * data will contain the element type OID.  Need to think through
00143  * type-safety issues before allowing it, however.
00144  */
00145 Datum
00146 anyarray_recv(PG_FUNCTION_ARGS)
00147 {
00148     ereport(ERROR,
00149             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00150              errmsg("cannot accept a value of type anyarray")));
00151 
00152     PG_RETURN_VOID();           /* keep compiler quiet */
00153 }
00154 
00155 /*
00156  * anyarray_send        - binary output routine for pseudo-type ANYARRAY.
00157  *
00158  * We may as well allow this, since array_send will in fact work.
00159  */
00160 Datum
00161 anyarray_send(PG_FUNCTION_ARGS)
00162 {
00163     return array_send(fcinfo);
00164 }
00165 
00166 
00167 /*
00168  * anyenum_in       - input routine for pseudo-type ANYENUM.
00169  */
00170 Datum
00171 anyenum_in(PG_FUNCTION_ARGS)
00172 {
00173     ereport(ERROR,
00174             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00175              errmsg("cannot accept a value of type anyenum")));
00176 
00177     PG_RETURN_VOID();           /* keep compiler quiet */
00178 }
00179 
00180 /*
00181  * anyenum_out      - output routine for pseudo-type ANYENUM.
00182  *
00183  * We may as well allow this, since enum_out will in fact work.
00184  */
00185 Datum
00186 anyenum_out(PG_FUNCTION_ARGS)
00187 {
00188     return enum_out(fcinfo);
00189 }
00190 
00191 /*
00192  * anyrange_in      - input routine for pseudo-type ANYRANGE.
00193  */
00194 Datum
00195 anyrange_in(PG_FUNCTION_ARGS)
00196 {
00197     ereport(ERROR,
00198             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00199              errmsg("cannot accept a value of type anyrange")));
00200 
00201     PG_RETURN_VOID();           /* keep compiler quiet */
00202 }
00203 
00204 /*
00205  * anyrange_out     - output routine for pseudo-type ANYRANGE.
00206  *
00207  * We may as well allow this, since range_out will in fact work.
00208  */
00209 Datum
00210 anyrange_out(PG_FUNCTION_ARGS)
00211 {
00212     return range_out(fcinfo);
00213 }
00214 
00215 /*
00216  * void_in      - input routine for pseudo-type VOID.
00217  *
00218  * We allow this so that PL functions can return VOID without any special
00219  * hack in the PL handler.  Whatever value the PL thinks it's returning
00220  * will just be ignored.
00221  */
00222 Datum
00223 void_in(PG_FUNCTION_ARGS)
00224 {
00225     PG_RETURN_VOID();           /* you were expecting something different? */
00226 }
00227 
00228 /*
00229  * void_out     - output routine for pseudo-type VOID.
00230  *
00231  * We allow this so that "SELECT function_returning_void(...)" works.
00232  */
00233 Datum
00234 void_out(PG_FUNCTION_ARGS)
00235 {
00236     PG_RETURN_CSTRING(pstrdup(""));
00237 }
00238 
00239 /*
00240  * void_recv    - binary input routine for pseudo-type VOID.
00241  *
00242  * Note that since we consume no bytes, an attempt to send anything but
00243  * an empty string will result in an "invalid message format" error.
00244  */
00245 Datum
00246 void_recv(PG_FUNCTION_ARGS)
00247 {
00248     PG_RETURN_VOID();
00249 }
00250 
00251 /*
00252  * void_send    - binary output routine for pseudo-type VOID.
00253  *
00254  * We allow this so that "SELECT function_returning_void(...)" works
00255  * even when binary output is requested.
00256  */
00257 Datum
00258 void_send(PG_FUNCTION_ARGS)
00259 {
00260     StringInfoData buf;
00261 
00262     /* send an empty string */
00263     pq_begintypsend(&buf);
00264     PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
00265 }
00266 
00267 
00268 /*
00269  * trigger_in       - input routine for pseudo-type TRIGGER.
00270  */
00271 Datum
00272 trigger_in(PG_FUNCTION_ARGS)
00273 {
00274     ereport(ERROR,
00275             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00276              errmsg("cannot accept a value of type trigger")));
00277 
00278     PG_RETURN_VOID();           /* keep compiler quiet */
00279 }
00280 
00281 /*
00282  * trigger_out      - output routine for pseudo-type TRIGGER.
00283  */
00284 Datum
00285 trigger_out(PG_FUNCTION_ARGS)
00286 {
00287     ereport(ERROR,
00288             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00289              errmsg("cannot display a value of type trigger")));
00290 
00291     PG_RETURN_VOID();           /* keep compiler quiet */
00292 }
00293 
00294 
00295 /*
00296  * event_trigger_in - input routine for pseudo-type event_trigger.
00297  */
00298 Datum
00299 event_trigger_in(PG_FUNCTION_ARGS)
00300 {
00301     ereport(ERROR,
00302             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00303              errmsg("cannot accept a value of type event_trigger")));
00304 
00305     PG_RETURN_VOID();           /* keep compiler quiet */
00306 }
00307 
00308 /*
00309  * event_trigger_out - output routine for pseudo-type event_trigger.
00310  */
00311 Datum
00312 event_trigger_out(PG_FUNCTION_ARGS)
00313 {
00314     ereport(ERROR,
00315             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00316              errmsg("cannot display a value of type event_trigger")));
00317 
00318     PG_RETURN_VOID();           /* keep compiler quiet */
00319 }
00320 
00321 
00322 /*
00323  * language_handler_in      - input routine for pseudo-type LANGUAGE_HANDLER.
00324  */
00325 Datum
00326 language_handler_in(PG_FUNCTION_ARGS)
00327 {
00328     ereport(ERROR,
00329             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00330              errmsg("cannot accept a value of type language_handler")));
00331 
00332     PG_RETURN_VOID();           /* keep compiler quiet */
00333 }
00334 
00335 /*
00336  * language_handler_out     - output routine for pseudo-type LANGUAGE_HANDLER.
00337  */
00338 Datum
00339 language_handler_out(PG_FUNCTION_ARGS)
00340 {
00341     ereport(ERROR,
00342             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00343              errmsg("cannot display a value of type language_handler")));
00344 
00345     PG_RETURN_VOID();           /* keep compiler quiet */
00346 }
00347 
00348 
00349 /*
00350  * fdw_handler_in       - input routine for pseudo-type FDW_HANDLER.
00351  */
00352 Datum
00353 fdw_handler_in(PG_FUNCTION_ARGS)
00354 {
00355     ereport(ERROR,
00356             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00357              errmsg("cannot accept a value of type fdw_handler")));
00358 
00359     PG_RETURN_VOID();           /* keep compiler quiet */
00360 }
00361 
00362 /*
00363  * fdw_handler_out      - output routine for pseudo-type FDW_HANDLER.
00364  */
00365 Datum
00366 fdw_handler_out(PG_FUNCTION_ARGS)
00367 {
00368     ereport(ERROR,
00369             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00370              errmsg("cannot display a value of type fdw_handler")));
00371 
00372     PG_RETURN_VOID();           /* keep compiler quiet */
00373 }
00374 
00375 
00376 /*
00377  * internal_in      - input routine for pseudo-type INTERNAL.
00378  */
00379 Datum
00380 internal_in(PG_FUNCTION_ARGS)
00381 {
00382     ereport(ERROR,
00383             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00384              errmsg("cannot accept a value of type internal")));
00385 
00386     PG_RETURN_VOID();           /* keep compiler quiet */
00387 }
00388 
00389 /*
00390  * internal_out     - output routine for pseudo-type INTERNAL.
00391  */
00392 Datum
00393 internal_out(PG_FUNCTION_ARGS)
00394 {
00395     ereport(ERROR,
00396             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00397              errmsg("cannot display a value of type internal")));
00398 
00399     PG_RETURN_VOID();           /* keep compiler quiet */
00400 }
00401 
00402 
00403 /*
00404  * opaque_in        - input routine for pseudo-type OPAQUE.
00405  */
00406 Datum
00407 opaque_in(PG_FUNCTION_ARGS)
00408 {
00409     ereport(ERROR,
00410             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00411              errmsg("cannot accept a value of type opaque")));
00412 
00413     PG_RETURN_VOID();           /* keep compiler quiet */
00414 }
00415 
00416 /*
00417  * opaque_out       - output routine for pseudo-type OPAQUE.
00418  */
00419 Datum
00420 opaque_out(PG_FUNCTION_ARGS)
00421 {
00422     ereport(ERROR,
00423             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00424              errmsg("cannot display a value of type opaque")));
00425 
00426     PG_RETURN_VOID();           /* keep compiler quiet */
00427 }
00428 
00429 
00430 /*
00431  * anyelement_in        - input routine for pseudo-type ANYELEMENT.
00432  */
00433 Datum
00434 anyelement_in(PG_FUNCTION_ARGS)
00435 {
00436     ereport(ERROR,
00437             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00438              errmsg("cannot accept a value of type anyelement")));
00439 
00440     PG_RETURN_VOID();           /* keep compiler quiet */
00441 }
00442 
00443 /*
00444  * anyelement_out       - output routine for pseudo-type ANYELEMENT.
00445  */
00446 Datum
00447 anyelement_out(PG_FUNCTION_ARGS)
00448 {
00449     ereport(ERROR,
00450             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00451              errmsg("cannot display a value of type anyelement")));
00452 
00453     PG_RETURN_VOID();           /* keep compiler quiet */
00454 }
00455 
00456 /*
00457  * anynonarray_in       - input routine for pseudo-type ANYNONARRAY.
00458  */
00459 Datum
00460 anynonarray_in(PG_FUNCTION_ARGS)
00461 {
00462     ereport(ERROR,
00463             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00464              errmsg("cannot accept a value of type anynonarray")));
00465 
00466     PG_RETURN_VOID();           /* keep compiler quiet */
00467 }
00468 
00469 /*
00470  * anynonarray_out      - output routine for pseudo-type ANYNONARRAY.
00471  */
00472 Datum
00473 anynonarray_out(PG_FUNCTION_ARGS)
00474 {
00475     ereport(ERROR,
00476             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00477              errmsg("cannot display a value of type anynonarray")));
00478 
00479     PG_RETURN_VOID();           /* keep compiler quiet */
00480 }
00481 
00482 /*
00483  * shell_in     - input routine for "shell" types (those not yet filled in).
00484  */
00485 Datum
00486 shell_in(PG_FUNCTION_ARGS)
00487 {
00488     ereport(ERROR,
00489             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00490              errmsg("cannot accept a value of a shell type")));
00491 
00492     PG_RETURN_VOID();           /* keep compiler quiet */
00493 }
00494 
00495 /*
00496  * shell_out        - output routine for "shell" types.
00497  */
00498 Datum
00499 shell_out(PG_FUNCTION_ARGS)
00500 {
00501     ereport(ERROR,
00502             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00503              errmsg("cannot display a value of a shell type")));
00504 
00505     PG_RETURN_VOID();           /* keep compiler quiet */
00506 }
00507 
00508 
00509 /*
00510  * pg_node_tree_in      - input routine for type PG_NODE_TREE.
00511  *
00512  * pg_node_tree isn't really a pseudotype --- it's real enough to be a table
00513  * column --- but it presently has no operations of its own, and disallows
00514  * input too, so its I/O functions seem to fit here as much as anywhere.
00515  */
00516 Datum
00517 pg_node_tree_in(PG_FUNCTION_ARGS)
00518 {
00519     /*
00520      * We disallow input of pg_node_tree values because the SQL functions that
00521      * operate on the type are not secure against malformed input.
00522      */
00523     ereport(ERROR,
00524             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00525              errmsg("cannot accept a value of type pg_node_tree")));
00526 
00527     PG_RETURN_VOID();           /* keep compiler quiet */
00528 }
00529 
00530 /*
00531  * pg_node_tree_out     - output routine for type PG_NODE_TREE.
00532  *
00533  * The internal representation is the same as TEXT, so just pass it off.
00534  */
00535 Datum
00536 pg_node_tree_out(PG_FUNCTION_ARGS)
00537 {
00538     return textout(fcinfo);
00539 }
00540 
00541 /*
00542  * pg_node_tree_recv        - binary input routine for type PG_NODE_TREE.
00543  */
00544 Datum
00545 pg_node_tree_recv(PG_FUNCTION_ARGS)
00546 {
00547     ereport(ERROR,
00548             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
00549              errmsg("cannot accept a value of type pg_node_tree")));
00550 
00551     PG_RETURN_VOID();           /* keep compiler quiet */
00552 }
00553 
00554 /*
00555  * pg_node_tree_send        - binary output routine for type PG_NODE_TREE.
00556  */
00557 Datum
00558 pg_node_tree_send(PG_FUNCTION_ARGS)
00559 {
00560     return textsend(fcinfo);
00561 }