]> granicus.if.org Git - postgresql/blobdiff - src/backend/utils/adt/pseudotypes.c
Add support for EUI-64 MAC addresses as macaddr8
[postgresql] / src / backend / utils / adt / pseudotypes.c
index ddb1bd2b71ccf577b7cec15942bd257e5ad83e23..be793539a3c84e60ff60e21bf07280403fa94f80 100644 (file)
@@ -6,12 +6,12 @@
  * A pseudo-type isn't really a type and never has any operations, but
  * we do need to supply input and output functions to satisfy the links
  * in the pseudo-type's entry in pg_type.  In most cases the functions
- * just throw an error if invoked.     (XXX the error messages here cover
+ * just throw an error if invoked.  (XXX the error messages here cover
  * the most common case, but might be confusing in some contexts.  Can
  * we do better?)
  *
  *
- * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
@@ -25,6 +25,7 @@
 #include "libpq/pqformat.h"
 #include "utils/array.h"
 #include "utils/builtins.h"
+#include "utils/rangetypes.h"
 
 
 /*
@@ -82,34 +83,6 @@ cstring_send(PG_FUNCTION_ARGS)
        PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
 }
 
-
-/*
- * any_in              - input routine for pseudo-type ANY.
- */
-Datum
-any_in(PG_FUNCTION_ARGS)
-{
-       ereport(ERROR,
-                       (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot accept a value of type any")));
-
-       PG_RETURN_VOID();                       /* keep compiler quiet */
-}
-
-/*
- * any_out             - output routine for pseudo-type ANY.
- */
-Datum
-any_out(PG_FUNCTION_ARGS)
-{
-       ereport(ERROR,
-                       (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot display a value of type any")));
-
-       PG_RETURN_VOID();                       /* keep compiler quiet */
-}
-
-
 /*
  * anyarray_in         - input routine for pseudo-type ANYARRAY.
  */
@@ -118,7 +91,7 @@ anyarray_in(PG_FUNCTION_ARGS)
 {
        ereport(ERROR,
                        (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot accept a value of type anyarray")));
+                        errmsg("cannot accept a value of type %s", "anyarray")));
 
        PG_RETURN_VOID();                       /* keep compiler quiet */
 }
@@ -138,7 +111,7 @@ anyarray_out(PG_FUNCTION_ARGS)
  * anyarray_recv               - binary input routine for pseudo-type ANYARRAY.
  *
  * XXX this could actually be made to work, since the incoming array
- * data will contain the element type OID.     Need to think through
+ * data will contain the element type OID.  Need to think through
  * type-safety issues before allowing it, however.
  */
 Datum
@@ -146,7 +119,7 @@ anyarray_recv(PG_FUNCTION_ARGS)
 {
        ereport(ERROR,
                        (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot accept a value of type anyarray")));
+                        errmsg("cannot accept a value of type %s", "anyarray")));
 
        PG_RETURN_VOID();                       /* keep compiler quiet */
 }
@@ -171,7 +144,7 @@ anyenum_in(PG_FUNCTION_ARGS)
 {
        ereport(ERROR,
                        (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot accept a value of type anyenum")));
+                        errmsg("cannot accept a value of type %s", "anyenum")));
 
        PG_RETURN_VOID();                       /* keep compiler quiet */
 }
@@ -187,12 +160,35 @@ anyenum_out(PG_FUNCTION_ARGS)
        return enum_out(fcinfo);
 }
 
+/*
+ * anyrange_in         - input routine for pseudo-type ANYRANGE.
+ */
+Datum
+anyrange_in(PG_FUNCTION_ARGS)
+{
+       ereport(ERROR,
+                       (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+                        errmsg("cannot accept a value of type %s", "anyrange")));
+
+       PG_RETURN_VOID();                       /* keep compiler quiet */
+}
+
+/*
+ * anyrange_out                - output routine for pseudo-type ANYRANGE.
+ *
+ * We may as well allow this, since range_out will in fact work.
+ */
+Datum
+anyrange_out(PG_FUNCTION_ARGS)
+{
+       return range_out(fcinfo);
+}
 
 /*
  * void_in             - input routine for pseudo-type VOID.
  *
  * We allow this so that PL functions can return VOID without any special
- * hack in the PL handler.     Whatever value the PL thinks it's returning
+ * hack in the PL handler.  Whatever value the PL thinks it's returning
  * will just be ignored.
  */
 Datum
@@ -240,271 +236,185 @@ void_send(PG_FUNCTION_ARGS)
        PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
 }
 
-
-/*
- * trigger_in          - input routine for pseudo-type TRIGGER.
- */
-Datum
-trigger_in(PG_FUNCTION_ARGS)
-{
-       ereport(ERROR,
-                       (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot accept a value of type trigger")));
-
-       PG_RETURN_VOID();                       /* keep compiler quiet */
-}
-
-/*
- * trigger_out         - output routine for pseudo-type TRIGGER.
- */
-Datum
-trigger_out(PG_FUNCTION_ARGS)
-{
-       ereport(ERROR,
-                       (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot display a value of type trigger")));
-
-       PG_RETURN_VOID();                       /* keep compiler quiet */
-}
-
-
-/*
- * language_handler_in         - input routine for pseudo-type LANGUAGE_HANDLER.
- */
-Datum
-language_handler_in(PG_FUNCTION_ARGS)
-{
-       ereport(ERROR,
-                       (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot accept a value of type language_handler")));
-
-       PG_RETURN_VOID();                       /* keep compiler quiet */
-}
-
-/*
- * language_handler_out                - output routine for pseudo-type LANGUAGE_HANDLER.
- */
-Datum
-language_handler_out(PG_FUNCTION_ARGS)
-{
-       ereport(ERROR,
-                       (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot display a value of type language_handler")));
-
-       PG_RETURN_VOID();                       /* keep compiler quiet */
-}
-
-
-/*
- * fdw_handler_in              - input routine for pseudo-type FDW_HANDLER.
- */
-Datum
-fdw_handler_in(PG_FUNCTION_ARGS)
-{
-       ereport(ERROR,
-                       (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot accept a value of type fdw_handler")));
-
-       PG_RETURN_VOID();                       /* keep compiler quiet */
-}
-
-/*
- * fdw_handler_out             - output routine for pseudo-type FDW_HANDLER.
- */
-Datum
-fdw_handler_out(PG_FUNCTION_ARGS)
-{
-       ereport(ERROR,
-                       (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot display a value of type fdw_handler")));
-
-       PG_RETURN_VOID();                       /* keep compiler quiet */
-}
-
-
 /*
- * internal_in         - input routine for pseudo-type INTERNAL.
+ * shell_in            - input routine for "shell" types (those not yet filled in).
  */
 Datum
-internal_in(PG_FUNCTION_ARGS)
+shell_in(PG_FUNCTION_ARGS)
 {
        ereport(ERROR,
                        (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot accept a value of type internal")));
+                        errmsg("cannot accept a value of a shell type")));
 
        PG_RETURN_VOID();                       /* keep compiler quiet */
 }
 
 /*
- * internal_out                - output routine for pseudo-type INTERNAL.
+ * shell_out           - output routine for "shell" types.
  */
 Datum
-internal_out(PG_FUNCTION_ARGS)
+shell_out(PG_FUNCTION_ARGS)
 {
        ereport(ERROR,
                        (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot display a value of type internal")));
+                        errmsg("cannot display a value of a shell type")));
 
        PG_RETURN_VOID();                       /* keep compiler quiet */
 }
 
 
 /*
- * opaque_in           - input routine for pseudo-type OPAQUE.
- */
-Datum
-opaque_in(PG_FUNCTION_ARGS)
-{
-       ereport(ERROR,
-                       (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot accept a value of type opaque")));
-
-       PG_RETURN_VOID();                       /* keep compiler quiet */
-}
-
-/*
- * opaque_out          - output routine for pseudo-type OPAQUE.
+ * pg_node_tree_in             - input routine for type PG_NODE_TREE.
+ *
+ * pg_node_tree isn't really a pseudotype --- it's real enough to be a table
+ * column --- but it presently has no operations of its own, and disallows
+ * input too, so its I/O functions seem to fit here as much as anywhere.
  */
 Datum
-opaque_out(PG_FUNCTION_ARGS)
+pg_node_tree_in(PG_FUNCTION_ARGS)
 {
+       /*
+        * We disallow input of pg_node_tree values because the SQL functions that
+        * operate on the type are not secure against malformed input.
+        */
        ereport(ERROR,
                        (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot display a value of type opaque")));
+                        errmsg("cannot accept a value of type %s", "pg_node_tree")));
 
        PG_RETURN_VOID();                       /* keep compiler quiet */
 }
 
 
 /*
- * anyelement_in               - input routine for pseudo-type ANYELEMENT.
+ * pg_node_tree_out            - output routine for type PG_NODE_TREE.
+ *
+ * The internal representation is the same as TEXT, so just pass it off.
  */
 Datum
-anyelement_in(PG_FUNCTION_ARGS)
+pg_node_tree_out(PG_FUNCTION_ARGS)
 {
-       ereport(ERROR,
-                       (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot accept a value of type anyelement")));
-
-       PG_RETURN_VOID();                       /* keep compiler quiet */
+       return textout(fcinfo);
 }
 
 /*
- * anyelement_out              - output routine for pseudo-type ANYELEMENT.
+ * pg_node_tree_recv           - binary input routine for type PG_NODE_TREE.
  */
 Datum
-anyelement_out(PG_FUNCTION_ARGS)
+pg_node_tree_recv(PG_FUNCTION_ARGS)
 {
        ereport(ERROR,
                        (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot display a value of type anyelement")));
+                        errmsg("cannot accept a value of type %s", "pg_node_tree")));
 
        PG_RETURN_VOID();                       /* keep compiler quiet */
 }
 
 /*
- * anynonarray_in              - input routine for pseudo-type ANYNONARRAY.
+ * pg_node_tree_send           - binary output routine for type PG_NODE_TREE.
  */
 Datum
-anynonarray_in(PG_FUNCTION_ARGS)
+pg_node_tree_send(PG_FUNCTION_ARGS)
 {
-       ereport(ERROR,
-                       (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot accept a value of type anynonarray")));
-
-       PG_RETURN_VOID();                       /* keep compiler quiet */
+       return textsend(fcinfo);
 }
 
 /*
- * anynonarray_out             - output routine for pseudo-type ANYNONARRAY.
+ * pg_ddl_command_in   - input routine for type PG_DDL_COMMAND.
+ *
+ * Like pg_node_tree, pg_ddl_command isn't really a pseudotype; it's here for
+ * the same reasons as that one.
  */
 Datum
-anynonarray_out(PG_FUNCTION_ARGS)
+pg_ddl_command_in(PG_FUNCTION_ARGS)
 {
+       /*
+        * Disallow input of pg_ddl_command value.
+        */
        ereport(ERROR,
                        (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot display a value of type anynonarray")));
+                        errmsg("cannot accept a value of type %s", "pg_ddl_command")));
 
        PG_RETURN_VOID();                       /* keep compiler quiet */
 }
 
 /*
- * shell_in            - input routine for "shell" types (those not yet filled in).
+ * pg_ddl_command_out          - output routine for type PG_DDL_COMMAND.
+ *
+ * We don't have any good way to output this type directly, so punt.
  */
 Datum
-shell_in(PG_FUNCTION_ARGS)
+pg_ddl_command_out(PG_FUNCTION_ARGS)
 {
        ereport(ERROR,
                        (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot accept a value of a shell type")));
+                        errmsg("cannot output a value of type %s", "pg_ddl_command")));
 
-       PG_RETURN_VOID();                       /* keep compiler quiet */
+       PG_RETURN_VOID();
 }
 
 /*
- * shell_out           - output routine for "shell" types.
+ * pg_ddl_command_recv         - binary input routine for type PG_DDL_COMMAND.
  */
 Datum
-shell_out(PG_FUNCTION_ARGS)
+pg_ddl_command_recv(PG_FUNCTION_ARGS)
 {
        ereport(ERROR,
                        (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot display a value of a shell type")));
+                        errmsg("cannot accept a value of type %s", "pg_ddl_command")));
 
-       PG_RETURN_VOID();                       /* keep compiler quiet */
+       PG_RETURN_VOID();
 }
 
-
 /*
- * pg_node_tree_in             - input routine for type PG_NODE_TREE.
- *
- * pg_node_tree isn't really a pseudotype --- it's real enough to be a table
- * column --- but it presently has no operations of its own, and disallows
- * input too, so its I/O functions seem to fit here as much as anywhere.
+ * pg_ddl_command_send         - binary output routine for type PG_DDL_COMMAND.
  */
 Datum
-pg_node_tree_in(PG_FUNCTION_ARGS)
+pg_ddl_command_send(PG_FUNCTION_ARGS)
 {
-       /*
-        * We disallow input of pg_node_tree values because the SQL functions that
-        * operate on the type are not secure against malformed input.
-        */
        ereport(ERROR,
                        (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot accept a value of type pg_node_tree")));
+                        errmsg("cannot output a value of type %s", "pg_ddl_command")));
 
-       PG_RETURN_VOID();                       /* keep compiler quiet */
-}
-
-/*
- * pg_node_tree_out            - output routine for type PG_NODE_TREE.
- *
- * The internal representation is the same as TEXT, so just pass it off.
- */
-Datum
-pg_node_tree_out(PG_FUNCTION_ARGS)
-{
-       return textout(fcinfo);
+       PG_RETURN_VOID();
 }
 
-/*
- * pg_node_tree_recv           - binary input routine for type PG_NODE_TREE.
- */
-Datum
-pg_node_tree_recv(PG_FUNCTION_ARGS)
-{
-       ereport(ERROR,
-                       (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                        errmsg("cannot accept a value of type pg_node_tree")));
-
-       PG_RETURN_VOID();                       /* keep compiler quiet */
-}
 
 /*
- * pg_node_tree_send           - binary output routine for type PG_NODE_TREE.
- */
-Datum
-pg_node_tree_send(PG_FUNCTION_ARGS)
-{
-       return textsend(fcinfo);
-}
+ * Generate input and output functions for a pseudotype that will reject all
+ * input and output attempts.
+ */
+#define PSEUDOTYPE_DUMMY_IO_FUNCS(typname) \
+\
+Datum \
+typname##_in(PG_FUNCTION_ARGS) \
+{ \
+       ereport(ERROR, \
+                       (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), \
+                        errmsg("cannot accept a value of type %s", #typname))); \
+\
+       PG_RETURN_VOID();                       /* keep compiler quiet */ \
+} \
+\
+Datum \
+typname##_out(PG_FUNCTION_ARGS) \
+{ \
+       ereport(ERROR, \
+                       (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), \
+                        errmsg("cannot display a value of type %s", #typname))); \
+\
+       PG_RETURN_VOID();                       /* keep compiler quiet */ \
+} \
+\
+extern int no_such_variable
+
+PSEUDOTYPE_DUMMY_IO_FUNCS(any);
+PSEUDOTYPE_DUMMY_IO_FUNCS(trigger);
+PSEUDOTYPE_DUMMY_IO_FUNCS(event_trigger);
+PSEUDOTYPE_DUMMY_IO_FUNCS(language_handler);
+PSEUDOTYPE_DUMMY_IO_FUNCS(fdw_handler);
+PSEUDOTYPE_DUMMY_IO_FUNCS(index_am_handler);
+PSEUDOTYPE_DUMMY_IO_FUNCS(tsm_handler);
+PSEUDOTYPE_DUMMY_IO_FUNCS(internal);
+PSEUDOTYPE_DUMMY_IO_FUNCS(opaque);
+PSEUDOTYPE_DUMMY_IO_FUNCS(anyelement);
+PSEUDOTYPE_DUMMY_IO_FUNCS(anynonarray);