From 1ab9b012bdf1f106792fc523e21b9ca8299bb8ed Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 22 Feb 2011 13:08:22 -0500 Subject: [PATCH] Allow binary I/O of type "void". MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit void_send is useful for the same reason that void_out doesn't throw error, namely that someone might do "select void_returning_func(...)" from a client that prefers to operate in binary mode. The void_recv function may or may not have any practical use, but we provide it for symmetry. Radosław Smogura --- src/backend/utils/adt/pseudotypes.c | 28 ++++++++++++++++++++++++++++ src/include/catalog/catversion.h | 2 +- src/include/catalog/pg_proc.h | 4 ++++ src/include/catalog/pg_type.h | 2 +- src/include/utils/builtins.h | 2 ++ 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/backend/utils/adt/pseudotypes.c b/src/backend/utils/adt/pseudotypes.c index d9329f8342..ddb1bd2b71 100644 --- a/src/backend/utils/adt/pseudotypes.c +++ b/src/backend/utils/adt/pseudotypes.c @@ -212,6 +212,34 @@ void_out(PG_FUNCTION_ARGS) PG_RETURN_CSTRING(pstrdup("")); } +/* + * void_recv - binary input routine for pseudo-type VOID. + * + * Note that since we consume no bytes, an attempt to send anything but + * an empty string will result in an "invalid message format" error. + */ +Datum +void_recv(PG_FUNCTION_ARGS) +{ + PG_RETURN_VOID(); +} + +/* + * void_send - binary output routine for pseudo-type VOID. + * + * We allow this so that "SELECT function_returning_void(...)" works + * even when binary output is requested. + */ +Datum +void_send(PG_FUNCTION_ARGS) +{ + StringInfoData buf; + + /* send an empty string */ + pq_begintypsend(&buf); + PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); +} + /* * trigger_in - input routine for pseudo-type TRIGGER. diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 989138169a..70106414cf 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 201102191 +#define CATALOG_VERSION_NO 201102221 #endif diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index 08949853f1..8c940bb74d 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -4226,6 +4226,10 @@ DATA(insert OID = 2502 ( anyarray_recv PGNSP PGUID 12 1 0 0 f f f t f s 1 0 DESCR("I/O"); DATA(insert OID = 2503 ( anyarray_send PGNSP PGUID 12 1 0 0 f f f t f s 1 0 17 "2277" _null_ _null_ _null_ _null_ anyarray_send _null_ _null_ _null_ )); DESCR("I/O"); +DATA(insert OID = 3120 ( void_recv PGNSP PGUID 12 1 0 0 f f f t f i 1 0 2278 "2281" _null_ _null_ _null_ _null_ void_recv _null_ _null_ _null_ )); +DESCR("I/O"); +DATA(insert OID = 3121 ( void_send PGNSP PGUID 12 1 0 0 f f f t f i 1 0 17 "2278" _null_ _null_ _null_ _null_ void_send _null_ _null_ _null_ )); +DESCR("I/O"); /* System-view support functions with pretty-print option */ DATA(insert OID = 2504 ( pg_get_ruledef PGNSP PGUID 12 1 0 0 f f f t f s 2 0 25 "26 16" _null_ _null_ _null_ _null_ pg_get_ruledef_ext _null_ _null_ _null_ )); diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h index 0f7312e495..9baed6c769 100644 --- a/src/include/catalog/pg_type.h +++ b/src/include/catalog/pg_type.h @@ -615,7 +615,7 @@ DATA(insert OID = 2276 ( any PGNSP PGUID 4 t p P f t \054 0 0 0 any_in any_ou #define ANYOID 2276 DATA(insert OID = 2277 ( anyarray PGNSP PGUID -1 f p P f t \054 0 0 0 anyarray_in anyarray_out anyarray_recv anyarray_send - - - d x f 0 -1 0 0 _null_ _null_ )); #define ANYARRAYOID 2277 -DATA(insert OID = 2278 ( void PGNSP PGUID 4 t p P f t \054 0 0 0 void_in void_out - - - - - i p f 0 -1 0 0 _null_ _null_ )); +DATA(insert OID = 2278 ( void PGNSP PGUID 4 t p P f t \054 0 0 0 void_in void_out void_recv void_send - - - i p f 0 -1 0 0 _null_ _null_ )); #define VOIDOID 2278 DATA(insert OID = 2279 ( trigger PGNSP PGUID 4 t p P f t \054 0 0 0 trigger_in trigger_out - - - - - i p f 0 -1 0 0 _null_ _null_ )); #define TRIGGEROID 2279 diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h index 8392be6208..8652ba03a0 100644 --- a/src/include/utils/builtins.h +++ b/src/include/utils/builtins.h @@ -504,6 +504,8 @@ extern Datum anyenum_in(PG_FUNCTION_ARGS); extern Datum anyenum_out(PG_FUNCTION_ARGS); extern Datum void_in(PG_FUNCTION_ARGS); extern Datum void_out(PG_FUNCTION_ARGS); +extern Datum void_recv(PG_FUNCTION_ARGS); +extern Datum void_send(PG_FUNCTION_ARGS); extern Datum trigger_in(PG_FUNCTION_ARGS); extern Datum trigger_out(PG_FUNCTION_ARGS); extern Datum language_handler_in(PG_FUNCTION_ARGS); -- 2.40.0