Commit ba1e066e authored by Tom Lane's avatar Tom Lane

Implement array_send/array_recv (binary I/O for arrays). This exposed

the folly of not passing element type to typsend/typreceive, so fix that.
parent b1ee615a
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_type.sgml,v 1.42 2003/05/08 22:19:56 tgl Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_type.sgml,v 1.43 2003/05/09 23:01:44 tgl Exp $
PostgreSQL documentation
-->
......@@ -117,15 +117,20 @@ CREATE TYPE <replaceable class="parameter">typename</replaceable> (
representation is in the machine's native byte order.) The receive
function should perform adequate checking to ensure that the value is
valid.
The receive function should be declared as taking one argument of type
<type>internal</type> and returning a value of the data type itself.
(The argument actually supplied is a pointer to a StringInfo buffer
holding the received byte string.) Similarly, the optional
The receive function may be declared as taking one argument of type
<type>internal</type>, or two arguments of types <type>internal</type>
and <type>oid</type>. It must return a value of the data type itself.
(The first argument is a pointer to a StringInfo buffer
holding the received byte string; the optional second argument is the
element type in case this is an array type.) Similarly, the optional
<replaceable class="parameter">send_function</replaceable> converts
from the internal representation to the external binary representation.
If this function is not supplied, the type cannot participate in binary
output. The send function should be declared as taking one argument of the
new data type and returning type <type>bytea</type>.
output. The send function may be
declared as taking one argument of the new data type, or as taking
two arguments of which the second is type <type>oid</type>.
The second argument is again the array element type for array types.
The send function must return type <type>bytea</type>.
</para>
<para>
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/typecmds.c,v 1.35 2003/05/08 22:19:56 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/typecmds.c,v 1.36 2003/05/09 23:01:45 tgl Exp $
*
* DESCRIPTION
* The "DefineFoo" routines take the parse tree and pick out the
......@@ -911,7 +911,8 @@ findTypeReceiveFunction(List *procname, Oid typeOid)
Oid procOid;
/*
* Receive functions take a single argument of type INTERNAL.
* Receive functions can take a single argument of type INTERNAL, or
* two arguments (internal, oid).
*/
MemSet(argList, 0, FUNC_MAX_ARGS * sizeof(Oid));
......@@ -921,6 +922,12 @@ findTypeReceiveFunction(List *procname, Oid typeOid)
if (OidIsValid(procOid))
return procOid;
argList[1] = OIDOID;
procOid = LookupFuncName(procname, 2, argList);
if (OidIsValid(procOid))
return procOid;
func_error("TypeCreate", procname, 1, argList, NULL);
return InvalidOid; /* keep compiler quiet */
......@@ -933,7 +940,8 @@ findTypeSendFunction(List *procname, Oid typeOid)
Oid procOid;
/*
* Send functions take a single argument of the type.
* Send functions can take a single argument of the type, or two
* arguments (data value, element OID).
*/
MemSet(argList, 0, FUNC_MAX_ARGS * sizeof(Oid));
......@@ -943,6 +951,12 @@ findTypeSendFunction(List *procname, Oid typeOid)
if (OidIsValid(procOid))
return procOid;
argList[1] = OIDOID;
procOid = LookupFuncName(procname, 2, argList);
if (OidIsValid(procOid))
return procOid;
func_error("TypeCreate", procname, 1, argList, NULL);
return InvalidOid; /* keep compiler quiet */
......
This diff is collapsed.
......@@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: catversion.h,v 1.189 2003/05/09 21:19:49 tgl Exp $
* $Id: catversion.h,v 1.190 2003/05/09 23:01:45 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -53,6 +53,6 @@
*/
/* yyyymmddN */
#define CATALOG_VERSION_NO 200305092
#define CATALOG_VERSION_NO 200305093
#endif
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: pg_proc.h,v 1.296 2003/05/09 21:19:49 tgl Exp $
* $Id: pg_proc.h,v 1.297 2003/05/09 23:01:45 tgl Exp $
*
* NOTES
* The script catalog/genbki.sh reads this file and generates .bki
......@@ -3153,9 +3153,9 @@ DATA(insert OID = 2311 ( md5 PGNSP PGUID 12 f f t f i 1 25 "25" md5_text -
DESCR("calculates md5 hash");
DATA(insert OID = 2400 ( array_recv PGNSP PGUID 12 f f t f s 1 2277 "2281" array_recv - _null_ ));
DATA(insert OID = 2400 ( array_recv PGNSP PGUID 12 f f t f s 2 2277 "2281 26" array_recv - _null_ ));
DESCR("I/O");
DATA(insert OID = 2401 ( array_send PGNSP PGUID 12 f f t f s 1 17 "2277" array_send - _null_ ));
DATA(insert OID = 2401 ( array_send PGNSP PGUID 12 f f t f s 2 17 "2277 26" array_send - _null_ ));
DESCR("I/O");
DATA(insert OID = 2402 ( record_recv PGNSP PGUID 12 f f t f i 1 2249 "2281" record_recv - _null_ ));
DESCR("I/O");
......
......@@ -143,7 +143,9 @@ WHERE p1.typoutput = p2.oid AND p1.typtype in ('b', 'p') AND NOT
SELECT p1.oid, p1.typname, p2.oid, p2.proname
FROM pg_type AS p1, pg_proc AS p2
WHERE p1.typreceive = p2.oid AND p1.typtype in ('b', 'p') AND NOT
(p2.pronargs = 1 AND p2.proargtypes[0] = 'internal'::regtype);
((p2.pronargs = 1 AND p2.proargtypes[0] = 'internal'::regtype) OR
(p2.pronargs = 2 AND p2.proargtypes[0] = 'internal'::regtype AND
p2.proargtypes[1] = 'oid'::regtype));
oid | typname | oid | proname
-----+---------+-----+---------
(0 rows)
......
......@@ -114,7 +114,9 @@ WHERE p1.typoutput = p2.oid AND p1.typtype in ('b', 'p') AND NOT
SELECT p1.oid, p1.typname, p2.oid, p2.proname
FROM pg_type AS p1, pg_proc AS p2
WHERE p1.typreceive = p2.oid AND p1.typtype in ('b', 'p') AND NOT
(p2.pronargs = 1 AND p2.proargtypes[0] = 'internal'::regtype);
((p2.pronargs = 1 AND p2.proargtypes[0] = 'internal'::regtype) OR
(p2.pronargs = 2 AND p2.proargtypes[0] = 'internal'::regtype AND
p2.proargtypes[1] = 'oid'::regtype));
-- As of 7.4, this check finds refcursor, which is borrowing
-- other types' I/O routines
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment