<!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/create_type.sgml,v 1.50 2004/05/16 23:22:07 neilc Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/create_type.sgml,v 1.51 2004/06/06 00:41:25 tgl Exp $
PostgreSQL documentation
-->
or as taking three arguments of types
<type>cstring</type>, <type>oid</type>, <type>integer</type>.
The first argument is the input text as a C string, the second
- argument is the element type in case this is an array type,
+ argument is the element type's OID in case this is an array type
+ (or the type's own OID for a composite type),
and the third is the <literal>typmod</> of the destination column, if known.
The input function should return a value of the data type itself.
The output 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 second argument is again the array element type OID for array types
+ or the type OID for composite types.
The output function should return type <type>cstring</type>.
</para>
and <type>oid</type>. It must return a value of the data type itself.
(The first argument is a pointer to a <type>StringInfo</type> buffer
holding the received byte string; the optional second argument is the
- element type in case this is an array type.) Similarly, the optional
+ element type OID in case this is an array type, or the type's own OID for a
+ composite 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 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 second argument is again the array element type OID for array types
+ or the type OID for composite types.
The send function must return type <type>bytea</type>.
</para>
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/common/printtup.c,v 1.82 2004/06/04 20:35:21 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/common/printtup.c,v 1.83 2004/06/06 00:41:25 tgl Exp $
*
*-------------------------------------------------------------------------
*/
{ /* Per-attribute information */
Oid typoutput; /* Oid for the type's text output fn */
Oid typsend; /* Oid for the type's binary output fn */
- Oid typelem; /* typelem value to pass to the output fn */
+ Oid typioparam; /* param to pass to the output fn */
bool typisvarlena; /* is it varlena (ie possibly toastable)? */
int16 format; /* format code for this column */
FmgrInfo finfo; /* Precomputed call info for output fn */
{
getTypeOutputInfo(typeinfo->attrs[i]->atttypid,
&thisState->typoutput,
- &thisState->typelem,
+ &thisState->typioparam,
&thisState->typisvarlena);
fmgr_info(thisState->typoutput, &thisState->finfo);
}
{
getTypeBinaryOutputInfo(typeinfo->attrs[i]->atttypid,
&thisState->typsend,
- &thisState->typelem,
+ &thisState->typioparam,
&thisState->typisvarlena);
fmgr_info(thisState->typsend, &thisState->finfo);
}
outputstr = DatumGetCString(FunctionCall3(&thisState->finfo,
attr,
- ObjectIdGetDatum(thisState->typelem),
+ ObjectIdGetDatum(thisState->typioparam),
Int32GetDatum(typeinfo->attrs[i]->atttypmod)));
pq_sendcountedtext(&buf, outputstr, strlen(outputstr), false);
pfree(outputstr);
outputbytes = DatumGetByteaP(FunctionCall2(&thisState->finfo,
attr,
- ObjectIdGetDatum(thisState->typelem)));
+ ObjectIdGetDatum(thisState->typioparam)));
/* We assume the result will not have been toasted */
pq_sendint(&buf, VARSIZE(outputbytes) - VARHDRSZ, 4);
pq_sendbytes(&buf, VARDATA(outputbytes),
outputstr = DatumGetCString(FunctionCall3(&thisState->finfo,
attr,
- ObjectIdGetDatum(thisState->typelem),
+ ObjectIdGetDatum(thisState->typioparam),
Int32GetDatum(typeinfo->attrs[i]->atttypmod)));
pq_sendcountedtext(&buf, outputstr, strlen(outputstr), true);
pfree(outputstr);
char *value;
bool isnull;
Oid typoutput,
- typelem;
+ typioparam;
bool typisvarlena;
for (i = 0; i < natts; ++i)
if (isnull)
continue;
getTypeOutputInfo(typeinfo->attrs[i]->atttypid,
- &typoutput, &typelem, &typisvarlena);
+ &typoutput, &typioparam, &typisvarlena);
/*
* If we have a toasted datum, forcibly detoast it here to avoid
value = DatumGetCString(OidFunctionCall3(typoutput,
attr,
- ObjectIdGetDatum(typelem),
+ ObjectIdGetDatum(typioparam),
Int32GetDatum(typeinfo->attrs[i]->atttypmod)));
printatt((unsigned) i + 1, typeinfo->attrs[i], value);
outputbytes = DatumGetByteaP(FunctionCall2(&thisState->finfo,
attr,
- ObjectIdGetDatum(thisState->typelem)));
+ ObjectIdGetDatum(thisState->typioparam)));
/* We assume the result will not have been toasted */
pq_sendint(&buf, VARSIZE(outputbytes) - VARHDRSZ, 4);
pq_sendbytes(&buf, VARDATA(outputbytes),
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.183 2004/06/03 02:08:02 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.184 2004/06/06 00:41:26 tgl Exp $
*
*-------------------------------------------------------------------------
*/
void
InsertOneValue(char *value, int i)
{
- int typeindex;
+ Oid typoid;
+ Oid typioparam;
+ Oid typinput;
+ Oid typoutput;
char *prt;
- struct typmap **app;
AssertArg(i >= 0 || i < MAXATTR);
if (Typ != NULL)
{
+ struct typmap **app;
struct typmap *ap;
- elog(DEBUG4, "Typ != NULL");
+ elog(DEBUG5, "Typ != NULL");
+ typoid = boot_reldesc->rd_att->attrs[i]->atttypid;
app = Typ;
- while (*app && (*app)->am_oid != boot_reldesc->rd_att->attrs[i]->atttypid)
+ while (*app && (*app)->am_oid != typoid)
++app;
ap = *app;
if (ap == NULL)
- {
- elog(FATAL, "could not find atttypid %u in Typ list",
- boot_reldesc->rd_att->attrs[i]->atttypid);
- }
- values[i] = OidFunctionCall3(ap->am_typ.typinput,
- CStringGetDatum(value),
- ObjectIdGetDatum(ap->am_typ.typelem),
- Int32GetDatum(-1));
- prt = DatumGetCString(OidFunctionCall3(ap->am_typ.typoutput,
- values[i],
- ObjectIdGetDatum(ap->am_typ.typelem),
- Int32GetDatum(-1)));
- elog(DEBUG4, " -> %s", prt);
- pfree(prt);
+ elog(ERROR, "could not find atttypid %u in Typ list", typoid);
+
+ /* XXX this should match getTypeIOParam() */
+ if (ap->am_typ.typtype == 'c')
+ typioparam = typoid;
+ else
+ typioparam = ap->am_typ.typelem;
+
+ typinput = ap->am_typ.typinput;
+ typoutput = ap->am_typ.typoutput;
}
else
{
+ int typeindex;
+
+ /* XXX why is typoid determined differently in this path? */
+ typoid = attrtypes[i]->atttypid;
for (typeindex = 0; typeindex < n_types; typeindex++)
{
- if (TypInfo[typeindex].oid == attrtypes[i]->atttypid)
+ if (TypInfo[typeindex].oid == typoid)
break;
}
if (typeindex >= n_types)
- elog(ERROR, "type oid %u not found", attrtypes[i]->atttypid);
- elog(DEBUG4, "Typ == NULL, typeindex = %u", typeindex);
- values[i] = OidFunctionCall3(TypInfo[typeindex].inproc,
- CStringGetDatum(value),
- ObjectIdGetDatum(TypInfo[typeindex].elem),
- Int32GetDatum(-1));
- prt = DatumGetCString(OidFunctionCall3(TypInfo[typeindex].outproc,
- values[i],
- ObjectIdGetDatum(TypInfo[typeindex].elem),
- Int32GetDatum(-1)));
- elog(DEBUG4, " -> %s", prt);
- pfree(prt);
+ elog(ERROR, "type oid %u not found", typoid);
+ elog(DEBUG5, "Typ == NULL, typeindex = %u", typeindex);
+
+ /* XXX there are no composite types in TypInfo */
+ typioparam = TypInfo[typeindex].elem;
+
+ typinput = TypInfo[typeindex].inproc;
+ typoutput = TypInfo[typeindex].outproc;
}
- elog(DEBUG4, "inserted");
+
+ values[i] = OidFunctionCall3(typinput,
+ CStringGetDatum(value),
+ ObjectIdGetDatum(typioparam),
+ Int32GetDatum(-1));
+ prt = DatumGetCString(OidFunctionCall3(typoutput,
+ values[i],
+ ObjectIdGetDatum(typioparam),
+ Int32GetDatum(-1)));
+ elog(DEBUG4, "inserted -> %s", prt);
+ pfree(prt);
}
/* ----------------
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.225 2004/06/05 19:48:07 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.226 2004/06/06 00:41:26 tgl Exp $
*
*-------------------------------------------------------------------------
*/
char *quote, char *escape,
CopyReadResult *result, bool *isnull);
static Datum CopyReadBinaryAttribute(int column_no, FmgrInfo *flinfo,
- Oid typelem, bool *isnull);
+ Oid typioparam, bool *isnull);
static void CopyAttributeOut(char *string, char *delim);
static void CopyAttributeOutCSV(char *string, char *delim, char *quote,
char *escape, bool force_quote);
Form_pg_attribute *attr;
FmgrInfo *out_functions;
bool *force_quote;
- Oid *elements;
+ Oid *typioparams;
bool *isvarlena;
char *string;
Snapshot mySnapshot;
* Get info about the columns we need to process.
*/
out_functions = (FmgrInfo *) palloc(num_phys_attrs * sizeof(FmgrInfo));
- elements = (Oid *) palloc(num_phys_attrs * sizeof(Oid));
+ typioparams = (Oid *) palloc(num_phys_attrs * sizeof(Oid));
isvarlena = (bool *) palloc(num_phys_attrs * sizeof(bool));
force_quote = (bool *) palloc(num_phys_attrs * sizeof(bool));
foreach(cur, attnumlist)
if (binary)
getTypeBinaryOutputInfo(attr[attnum - 1]->atttypid,
- &out_func_oid, &elements[attnum - 1],
+ &out_func_oid, &typioparams[attnum - 1],
&isvarlena[attnum - 1]);
else
getTypeOutputInfo(attr[attnum - 1]->atttypid,
- &out_func_oid, &elements[attnum - 1],
+ &out_func_oid, &typioparams[attnum - 1],
&isvarlena[attnum - 1]);
fmgr_info(out_func_oid, &out_functions[attnum - 1]);
{
string = DatumGetCString(FunctionCall3(&out_functions[attnum - 1],
value,
- ObjectIdGetDatum(elements[attnum - 1]),
+ ObjectIdGetDatum(typioparams[attnum - 1]),
Int32GetDatum(attr[attnum - 1]->atttypmod)));
if (csv_mode)
{
outputbytes = DatumGetByteaP(FunctionCall2(&out_functions[attnum - 1],
value,
- ObjectIdGetDatum(elements[attnum - 1])));
+ ObjectIdGetDatum(typioparams[attnum - 1])));
/* We assume the result will not have been toasted */
CopySendInt32(VARSIZE(outputbytes) - VARHDRSZ);
CopySendData(VARDATA(outputbytes),
MemoryContextDelete(mycontext);
pfree(out_functions);
- pfree(elements);
+ pfree(typioparams);
pfree(isvarlena);
pfree(force_quote);
}
num_defaults;
FmgrInfo *in_functions;
FmgrInfo oid_in_function;
- Oid *elements;
- Oid oid_in_element;
+ Oid *typioparams;
+ Oid oid_typioparam;
ExprState **constraintexprs;
bool *force_notnull;
bool hasConstraints = false;
* (Which input function we use depends on text/binary format choice.)
*/
in_functions = (FmgrInfo *) palloc(num_phys_attrs * sizeof(FmgrInfo));
- elements = (Oid *) palloc(num_phys_attrs * sizeof(Oid));
+ typioparams = (Oid *) palloc(num_phys_attrs * sizeof(Oid));
defmap = (int *) palloc(num_phys_attrs * sizeof(int));
defexprs = (ExprState **) palloc(num_phys_attrs * sizeof(ExprState *));
constraintexprs = (ExprState **) palloc0(num_phys_attrs * sizeof(ExprState *));
if (attr[attnum - 1]->attisdropped)
continue;
- /* Fetch the input function and typelem info */
+ /* Fetch the input function and typioparam info */
if (binary)
getTypeBinaryInputInfo(attr[attnum - 1]->atttypid,
- &in_func_oid, &elements[attnum - 1]);
+ &in_func_oid, &typioparams[attnum - 1]);
else
getTypeInputInfo(attr[attnum - 1]->atttypid,
- &in_func_oid, &elements[attnum - 1]);
+ &in_func_oid, &typioparams[attnum - 1]);
fmgr_info(in_func_oid, &in_functions[attnum - 1]);
if (list_member_int(force_notnull_atts, attnum))
if (file_has_oids && binary)
{
getTypeBinaryInputInfo(OIDOID,
- &in_func_oid, &oid_in_element);
+ &in_func_oid, &oid_typioparam);
fmgr_info(in_func_oid, &oid_in_function);
}
copy_attname = NameStr(attr[m]->attname);
values[m] = FunctionCall3(&in_functions[m],
CStringGetDatum(string),
- ObjectIdGetDatum(elements[m]),
+ ObjectIdGetDatum(typioparams[m]),
Int32GetDatum(attr[m]->atttypmod));
nulls[m] = ' ';
copy_attname = NULL;
copy_attname = "oid";
loaded_oid =
DatumGetObjectId(CopyReadBinaryAttribute(0,
- &oid_in_function,
- oid_in_element,
+ &oid_in_function,
+ oid_typioparam,
&isnull));
if (isnull || loaded_oid == InvalidOid)
ereport(ERROR,
i++;
values[m] = CopyReadBinaryAttribute(i,
&in_functions[m],
- elements[m],
+ typioparams[m],
&isnull);
nulls[m] = isnull ? 'n' : ' ';
copy_attname = NULL;
pfree(nulls);
pfree(in_functions);
- pfree(elements);
+ pfree(typioparams);
pfree(defmap);
pfree(defexprs);
pfree(constraintexprs);
* Read a binary attribute
*/
static Datum
-CopyReadBinaryAttribute(int column_no, FmgrInfo *flinfo, Oid typelem,
+CopyReadBinaryAttribute(int column_no, FmgrInfo *flinfo, Oid typioparam,
bool *isnull)
{
int32 fld_size;
/* Call the column type's binary input converter */
result = FunctionCall2(flinfo,
PointerGetDatum(&attribute_buf),
- ObjectIdGetDatum(typelem));
+ ObjectIdGetDatum(typioparam));
/* Trouble if it didn't eat the whole buffer */
if (attribute_buf.cursor != attribute_buf.len)
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/execTuples.c,v 1.79 2004/05/30 23:40:26 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/execTuples.c,v 1.80 2004/06/06 00:41:26 tgl Exp $
*
*-------------------------------------------------------------------------
*/
Oid atttypeid;
Oid attinfuncid;
FmgrInfo *attinfuncinfo;
- Oid *attelems;
+ Oid *attioparams;
int32 *atttypmods;
AttInMetadata *attinmeta;
* attribute
*/
attinfuncinfo = (FmgrInfo *) palloc0(natts * sizeof(FmgrInfo));
- attelems = (Oid *) palloc0(natts * sizeof(Oid));
+ attioparams = (Oid *) palloc0(natts * sizeof(Oid));
atttypmods = (int32 *) palloc0(natts * sizeof(int32));
for (i = 0; i < natts; i++)
if (!tupdesc->attrs[i]->attisdropped)
{
atttypeid = tupdesc->attrs[i]->atttypid;
- getTypeInputInfo(atttypeid, &attinfuncid, &attelems[i]);
+ getTypeInputInfo(atttypeid, &attinfuncid, &attioparams[i]);
fmgr_info(attinfuncid, &attinfuncinfo[i]);
atttypmods[i] = tupdesc->attrs[i]->atttypmod;
}
}
attinmeta->attinfuncs = attinfuncinfo;
- attinmeta->attelems = attelems;
+ attinmeta->attioparams = attioparams;
attinmeta->atttypmods = atttypmods;
return attinmeta;
Datum *dvalues;
char *nulls;
int i;
- Oid attelem;
+ Oid attioparam;
int32 atttypmod;
HeapTuple tuple;
/* Non-dropped attributes */
if (values[i] != NULL)
{
- attelem = attinmeta->attelems[i];
+ attioparam = attinmeta->attioparams[i];
atttypmod = attinmeta->atttypmods[i];
dvalues[i] = FunctionCall3(&attinmeta->attinfuncs[i],
CStringGetDatum(values[i]),
- ObjectIdGetDatum(attelem),
+ ObjectIdGetDatum(attioparam),
Int32GetDatum(atttypmod));
nulls[i] = ' ';
}
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/nodeAgg.c,v 1.121 2004/05/30 23:40:26 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/nodeAgg.c,v 1.122 2004/06/06 00:41:26 tgl Exp $
*
*-------------------------------------------------------------------------
*/
static Datum
GetAggInitVal(Datum textInitVal, Oid transtype)
{
- char *strInitVal;
- HeapTuple tup;
Oid typinput,
- typelem;
+ typioparam;
+ char *strInitVal;
Datum initVal;
+ getTypeInputInfo(transtype, &typinput, &typioparam);
strInitVal = DatumGetCString(DirectFunctionCall1(textout, textInitVal));
-
- tup = SearchSysCache(TYPEOID,
- ObjectIdGetDatum(transtype),
- 0, 0, 0);
- if (!HeapTupleIsValid(tup))
- elog(ERROR, "cache lookup failed for type %u", transtype);
-
- typinput = ((Form_pg_type) GETSTRUCT(tup))->typinput;
- typelem = ((Form_pg_type) GETSTRUCT(tup))->typelem;
- ReleaseSysCache(tup);
-
initVal = OidFunctionCall3(typinput,
CStringGetDatum(strInitVal),
- ObjectIdGetDatum(typelem),
+ ObjectIdGetDatum(typioparam),
Int32GetDatum(-1));
-
pfree(strInitVal);
return initVal;
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.116 2004/06/04 20:35:21 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.117 2004/06/06 00:41:26 tgl Exp $
*
*-------------------------------------------------------------------------
*/
bool isnull;
Oid typoid,
foutoid,
- typelem;
+ typioparam;
int32 typmod;
bool typisvarlena;
typmod = -1;
}
- getTypeOutputInfo(typoid, &foutoid, &typelem, &typisvarlena);
+ getTypeOutputInfo(typoid, &foutoid, &typioparam, &typisvarlena);
/*
* If we have a toasted datum, forcibly detoast it here to avoid
result = OidFunctionCall3(foutoid,
val,
- ObjectIdGetDatum(typelem),
+ ObjectIdGetDatum(typioparam),
Int32GetDatum(typmod));
/* Clean up detoasted copy, if any */
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/nodes/print.c,v 1.68 2004/05/30 23:40:27 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/nodes/print.c,v 1.69 2004/06/06 00:41:26 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
#include "postgres.h"
#include "access/printtup.h"
-#include "catalog/pg_type.h"
#include "lib/stringinfo.h"
#include "nodes/print.h"
#include "optimizer/clauses.h"
else if (IsA(expr, Const))
{
Const *c = (Const *) expr;
- HeapTuple typeTup;
Oid typoutput;
- Oid typelem;
+ Oid typioparam;
+ bool typIsVarlena;
char *outputstr;
if (c->constisnull)
return;
}
- typeTup = SearchSysCache(TYPEOID,
- ObjectIdGetDatum(c->consttype),
- 0, 0, 0);
- if (!HeapTupleIsValid(typeTup))
- elog(ERROR, "cache lookup failed for type %u", c->consttype);
- typoutput = ((Form_pg_type) GETSTRUCT(typeTup))->typoutput;
- typelem = ((Form_pg_type) GETSTRUCT(typeTup))->typelem;
- ReleaseSysCache(typeTup);
+ getTypeOutputInfo(c->consttype,
+ &typoutput, &typioparam, &typIsVarlena);
outputstr = DatumGetCString(OidFunctionCall3(typoutput,
c->constvalue,
- ObjectIdGetDatum(typelem),
+ ObjectIdGetDatum(typioparam),
Int32GetDatum(-1)));
printf("%s", outputstr);
pfree(outputstr);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.117 2004/05/30 23:40:35 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.118 2004/06/06 00:41:26 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
* If input is an untyped string constant, assume we can convert
- * it to anything except a class type.
+ * it to anything.
*/
if (inputTypeId == UNKNOWNOID)
- {
- if (ISCOMPLEX(targetTypeId))
- return false;
continue;
- }
/*
* If pg_cast shows that we can coerce, accept. This test now
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/parser/parse_type.c,v 1.68 2004/06/03 19:41:46 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/parser/parse_type.c,v 1.69 2004/06/06 00:41:26 tgl Exp $
*
*-------------------------------------------------------------------------
*/
return typtup->typrelid;
}
-#ifdef NOT_USED
-Oid
-typeTypElem(Type typ)
-{
- Form_pg_type typtup;
-
- typtup = (Form_pg_type) GETSTRUCT(typ);
-
- return typtup->typelem;
-}
-#endif
-
-#ifdef NOT_USED
-/* Given a type structure, return the in-conversion function of the type */
-Oid
-typeInfunc(Type typ)
-{
- Form_pg_type typtup;
-
- typtup = (Form_pg_type) GETSTRUCT(typ);
-
- return typtup->typinput;
-}
-#endif
-
-#ifdef NOT_USED
-/* Given a type structure, return the out-conversion function of the type */
-Oid
-typeOutfunc(Type typ)
-{
- Form_pg_type typtup;
-
- typtup = (Form_pg_type) GETSTRUCT(typ);
-
- return typtup->typoutput;
-}
-#endif
-
-/* Given a type structure and a string, returns the internal form of
- that string */
+/*
+ * Given a type structure and a string, returns the internal representation
+ * of that string
+ */
Datum
stringTypeDatum(Type tp, char *string, int32 atttypmod)
{
- Oid op;
- Oid typelem;
+ Oid typinput;
+ Oid typioparam;
- op = ((Form_pg_type) GETSTRUCT(tp))->typinput;
- typelem = ((Form_pg_type) GETSTRUCT(tp))->typelem; /* XXX - used for
- * array_in */
- return OidFunctionCall3(op,
+ typinput = ((Form_pg_type) GETSTRUCT(tp))->typinput;
+ typioparam = getTypeIOParam(tp);
+ return OidFunctionCall3(typinput,
CStringGetDatum(string),
- ObjectIdGetDatum(typelem),
+ ObjectIdGetDatum(typioparam),
Int32GetDatum(atttypmod));
}
-/* Given a type id, returns the out-conversion function of the type */
-#ifdef NOT_USED
-Oid
-typeidOutfunc(Oid type_id)
-{
- HeapTuple typeTuple;
- Form_pg_type type;
- Oid outfunc;
-
- typeTuple = SearchSysCache(TYPEOID,
- ObjectIdGetDatum(type_id),
- 0, 0, 0);
- if (!HeapTupleIsValid(typeTuple))
- elog(ERROR, "cache lookup failed for type %u", type_id);
-
- type = (Form_pg_type) GETSTRUCT(typeTuple);
- outfunc = type->typoutput;
- ReleaseSysCache(typeTuple);
- return outfunc;
-}
-#endif
-
/* given a typeid, return the type's typrelid (associated relation, if any) */
Oid
typeidTypeRelid(Oid type_id)
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/tcop/fastpath.c,v 1.72 2004/04/19 17:22:31 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/tcop/fastpath.c,v 1.73 2004/06/06 00:41:27 tgl Exp $
*
* NOTES
* This cruft is the server side of PQfn.
if (format == 0)
{
Oid typoutput,
- typelem;
+ typioparam;
bool typisvarlena;
char *outputstr;
- getTypeOutputInfo(rettype, &typoutput, &typelem, &typisvarlena);
+ getTypeOutputInfo(rettype, &typoutput, &typioparam, &typisvarlena);
outputstr = DatumGetCString(OidFunctionCall3(typoutput,
retval,
- ObjectIdGetDatum(typelem),
+ ObjectIdGetDatum(typioparam),
Int32GetDatum(-1)));
pq_sendcountedtext(&buf, outputstr, strlen(outputstr), false);
pfree(outputstr);
else if (format == 1)
{
Oid typsend,
- typelem;
+ typioparam;
bool typisvarlena;
bytea *outputbytes;
getTypeBinaryOutputInfo(rettype,
- &typsend, &typelem, &typisvarlena);
+ &typsend, &typioparam, &typisvarlena);
outputbytes = DatumGetByteaP(OidFunctionCall2(typsend,
retval,
- ObjectIdGetDatum(typelem)));
+ ObjectIdGetDatum(typioparam)));
/* We assume the result will not have been toasted */
pq_sendint(&buf, VARSIZE(outputbytes) - VARHDRSZ, 4);
pq_sendbytes(&buf, VARDATA(outputbytes),
if (aformat == 0)
{
- Oid typInput;
- Oid typElem;
+ Oid typinput;
+ Oid typioparam;
char *pstring;
- getTypeInputInfo(fip->argtypes[i], &typInput, &typElem);
+ getTypeInputInfo(fip->argtypes[i], &typinput, &typioparam);
/*
* Since stringinfo.c keeps a trailing null in place even for
pg_client_to_server((unsigned char *) abuf.data,
argsize);
fcinfo->arg[i] =
- OidFunctionCall3(typInput,
+ OidFunctionCall3(typinput,
CStringGetDatum(pstring),
- ObjectIdGetDatum(typElem),
+ ObjectIdGetDatum(typioparam),
Int32GetDatum(-1));
/* Free result of encoding conversion, if any */
if (pstring != abuf.data)
}
else if (aformat == 1)
{
- Oid typReceive;
- Oid typElem;
+ Oid typreceive;
+ Oid typioparam;
/* Call the argument type's binary input converter */
- getTypeBinaryInputInfo(fip->argtypes[i], &typReceive, &typElem);
+ getTypeBinaryInputInfo(fip->argtypes[i], &typreceive, &typioparam);
- fcinfo->arg[i] = OidFunctionCall2(typReceive,
+ fcinfo->arg[i] = OidFunctionCall2(typreceive,
PointerGetDatum(&abuf),
- ObjectIdGetDatum(typElem));
+ ObjectIdGetDatum(typioparam));
/* Trouble if it didn't eat the whole buffer */
if (abuf.cursor != abuf.len)
for (i = 0; i < nargs; ++i)
{
int argsize;
- Oid typReceive;
- Oid typElem;
+ Oid typreceive;
+ Oid typioparam;
argsize = pq_getmsgint(msgBuf, 4);
if (argsize == -1)
argsize);
/* Call the argument type's binary input converter */
- getTypeBinaryInputInfo(fip->argtypes[i], &typReceive, &typElem);
+ getTypeBinaryInputInfo(fip->argtypes[i], &typreceive, &typioparam);
- fcinfo->arg[i] = OidFunctionCall2(typReceive,
+ fcinfo->arg[i] = OidFunctionCall2(typreceive,
PointerGetDatum(&abuf),
- ObjectIdGetDatum(typElem));
+ ObjectIdGetDatum(typioparam));
/* Trouble if it didn't eat the whole buffer */
if (abuf.cursor != abuf.len)
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.418 2004/06/03 02:08:03 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.419 2004/06/06 00:41:27 tgl Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
if (pformat == 0)
{
- Oid typInput;
- Oid typElem;
+ Oid typinput;
+ Oid typioparam;
char *pstring;
- getTypeInputInfo(ptype, &typInput, &typElem);
+ getTypeInputInfo(ptype, &typinput, &typioparam);
/*
* We have to do encoding conversion before
pg_client_to_server((unsigned char *) pbuf.data,
plength);
params[i].value =
- OidFunctionCall3(typInput,
+ OidFunctionCall3(typinput,
CStringGetDatum(pstring),
- ObjectIdGetDatum(typElem),
+ ObjectIdGetDatum(typioparam),
Int32GetDatum(-1));
/* Free result of encoding conversion, if any */
if (pstring != pbuf.data)
}
else if (pformat == 1)
{
- Oid typReceive;
- Oid typElem;
+ Oid typreceive;
+ Oid typioparam;
/*
* Call the parameter type's binary input
* converter
*/
- getTypeBinaryInputInfo(ptype, &typReceive, &typElem);
+ getTypeBinaryInputInfo(ptype, &typreceive, &typioparam);
params[i].value =
- OidFunctionCall2(typReceive,
+ OidFunctionCall2(typreceive,
PointerGetDatum(&pbuf),
- ObjectIdGetDatum(typElem));
+ ObjectIdGetDatum(typioparam));
/* Trouble if it didn't eat the whole buffer */
if (pbuf.cursor != pbuf.len)
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.102 2004/01/07 18:56:28 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.103 2004/06/06 00:41:27 tgl Exp $
*
*-------------------------------------------------------------------------
*/
static int ArrayCount(char *str, int *dim, char typdelim);
static Datum *ReadArrayStr(char *arrayStr, int nitems, int ndim, int *dim,
- FmgrInfo *inputproc, Oid typelem, int32 typmod,
+ FmgrInfo *inputproc, Oid typioparam, int32 typmod,
char typdelim,
int typlen, bool typbyval, char typalign,
int *nbytes);
static Datum *ReadArrayBinary(StringInfo buf, int nitems,
- FmgrInfo *receiveproc, Oid typelem,
+ FmgrInfo *receiveproc, Oid typioparam,
int typlen, bool typbyval, char typalign,
int *nbytes);
static void CopyArrayEls(char *p, Datum *values, int nitems,
bool typbyval;
char typalign;
char typdelim;
- Oid typelem;
+ Oid typioparam;
char *string_save,
*p;
int i,
get_type_io_data(element_type, IOFunc_input,
&my_extra->typlen, &my_extra->typbyval,
&my_extra->typalign, &my_extra->typdelim,
- &my_extra->typelem, &my_extra->typiofunc);
+ &my_extra->typioparam, &my_extra->typiofunc);
fmgr_info_cxt(my_extra->typiofunc, &my_extra->proc,
fcinfo->flinfo->fn_mcxt);
my_extra->element_type = element_type;
typbyval = my_extra->typbyval;
typalign = my_extra->typalign;
typdelim = my_extra->typdelim;
- typelem = my_extra->typelem;
+ typioparam = my_extra->typioparam;
/* Make a modifiable copy of the input */
/* XXX why are we allocating an extra 2 bytes here? */
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("missing left brace")));
- dataPtr = ReadArrayStr(p, nitems, ndim, dim, &my_extra->proc, typelem,
+ dataPtr = ReadArrayStr(p, nitems, ndim, dim, &my_extra->proc, typioparam,
typmod, typdelim, typlen, typbyval, typalign,
&nbytes);
nbytes += ARR_OVERHEAD(ndim);
int ndim,
int *dim,
FmgrInfo *inputproc,
- Oid typelem,
+ Oid typioparam,
int32 typmod,
char typdelim,
int typlen,
values[i] = FunctionCall3(inputproc,
CStringGetDatum(itemstart),
- ObjectIdGetDatum(typelem),
+ ObjectIdGetDatum(typioparam),
Int32GetDatum(typmod));
}
bool typbyval;
char typalign;
char typdelim;
- Oid typelem;
+ Oid typioparam;
char *p,
*tmp,
*retval,
get_type_io_data(element_type, IOFunc_output,
&my_extra->typlen, &my_extra->typbyval,
&my_extra->typalign, &my_extra->typdelim,
- &my_extra->typelem, &my_extra->typiofunc);
+ &my_extra->typioparam, &my_extra->typiofunc);
fmgr_info_cxt(my_extra->typiofunc, &my_extra->proc,
fcinfo->flinfo->fn_mcxt);
my_extra->element_type = element_type;
typbyval = my_extra->typbyval;
typalign = my_extra->typalign;
typdelim = my_extra->typdelim;
- typelem = my_extra->typelem;
+ typioparam = my_extra->typioparam;
ndim = ARR_NDIM(v);
dim = ARR_DIMS(v);
itemvalue = fetch_att(p, typbyval, typlen);
values[i] = DatumGetCString(FunctionCall3(&my_extra->proc,
itemvalue,
- ObjectIdGetDatum(typelem),
+ ObjectIdGetDatum(typioparam),
Int32GetDatum(-1)));
p = att_addlength(p, typlen, PointerGetDatum(p));
p = (char *) att_align(p, typalign);
int typlen;
bool typbyval;
char typalign;
- Oid typelem;
+ Oid typioparam;
int i,
nitems;
int32 nbytes;
get_type_io_data(element_type, IOFunc_receive,
&my_extra->typlen, &my_extra->typbyval,
&my_extra->typalign, &my_extra->typdelim,
- &my_extra->typelem, &my_extra->typiofunc);
+ &my_extra->typioparam, &my_extra->typiofunc);
if (!OidIsValid(my_extra->typiofunc))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
typlen = my_extra->typlen;
typbyval = my_extra->typbyval;
typalign = my_extra->typalign;
- typelem = my_extra->typelem;
+ typioparam = my_extra->typioparam;
- dataPtr = ReadArrayBinary(buf, nitems, &my_extra->proc, typelem,
+ dataPtr = ReadArrayBinary(buf, nitems, &my_extra->proc, typioparam,
typlen, typbyval, typalign,
&nbytes);
nbytes += ARR_OVERHEAD(ndim);
ReadArrayBinary(StringInfo buf,
int nitems,
FmgrInfo *receiveproc,
- Oid typelem,
+ Oid typioparam,
int typlen,
bool typbyval,
char typalign,
/* Now call the element's receiveproc */
values[i] = FunctionCall2(receiveproc,
PointerGetDatum(&elem_buf),
- ObjectIdGetDatum(typelem));
+ ObjectIdGetDatum(typioparam));
/* Trouble if it didn't eat the whole buffer */
if (elem_buf.cursor != itemlen)
int typlen;
bool typbyval;
char typalign;
- Oid typelem;
+ Oid typioparam;
char *p;
int nitems,
i;
get_type_io_data(element_type, IOFunc_send,
&my_extra->typlen, &my_extra->typbyval,
&my_extra->typalign, &my_extra->typdelim,
- &my_extra->typelem, &my_extra->typiofunc);
+ &my_extra->typioparam, &my_extra->typiofunc);
if (!OidIsValid(my_extra->typiofunc))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
typlen = my_extra->typlen;
typbyval = my_extra->typbyval;
typalign = my_extra->typalign;
- typelem = my_extra->typelem;
+ typioparam = my_extra->typioparam;
ndim = ARR_NDIM(v);
dim = ARR_DIMS(v);
outputbytes = DatumGetByteaP(FunctionCall2(&my_extra->proc,
itemvalue,
- ObjectIdGetDatum(typelem)));
+ ObjectIdGetDatum(typioparam)));
/* We assume the result will not have been toasted */
pq_sendint(&buf, VARSIZE(outputbytes) - VARHDRSZ, 4);
pq_sendbytes(&buf, VARDATA(outputbytes),
* back to source text
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.169 2004/05/30 23:40:36 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.170 2004/06/06 00:41:27 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
get_const_expr(Const *constval, deparse_context *context)
{
StringInfo buf = context->buf;
- HeapTuple typetup;
- Form_pg_type typeStruct;
+ Oid typoutput;
+ Oid typioparam;
+ bool typIsVarlena;
char *extval;
char *valptr;
bool isfloat = false;
return;
}
- typetup = SearchSysCache(TYPEOID,
- ObjectIdGetDatum(constval->consttype),
- 0, 0, 0);
- if (!HeapTupleIsValid(typetup))
- elog(ERROR, "cache lookup failed for type %u", constval->consttype);
-
- typeStruct = (Form_pg_type) GETSTRUCT(typetup);
+ getTypeOutputInfo(constval->consttype,
+ &typoutput, &typioparam, &typIsVarlena);
- extval = DatumGetCString(OidFunctionCall3(typeStruct->typoutput,
+ extval = DatumGetCString(OidFunctionCall3(typoutput,
constval->constvalue,
- ObjectIdGetDatum(typeStruct->typelem),
+ ObjectIdGetDatum(typioparam),
Int32GetDatum(-1)));
switch (constval->consttype)
if (needlabel)
appendStringInfo(buf, "::%s",
format_type_with_typemod(constval->consttype, -1));
-
- ReleaseSysCache(typetup);
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.114 2004/05/30 23:40:36 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.115 2004/06/06 00:41:27 tgl Exp $
*
*-------------------------------------------------------------------------
*/
int typlen;
bool typbyval;
char typalign;
- Oid typelem;
+ Oid typioparam;
StringInfo result_str = makeStringInfo();
int i;
ArrayMetaState *my_extra;
get_type_io_data(element_type, IOFunc_output,
&my_extra->typlen, &my_extra->typbyval,
&my_extra->typalign, &my_extra->typdelim,
- &my_extra->typelem, &my_extra->typiofunc);
+ &my_extra->typioparam, &my_extra->typiofunc);
fmgr_info_cxt(my_extra->typiofunc, &my_extra->proc,
fcinfo->flinfo->fn_mcxt);
my_extra->element_type = element_type;
typlen = my_extra->typlen;
typbyval = my_extra->typbyval;
typalign = my_extra->typalign;
- typelem = my_extra->typelem;
+ typioparam = my_extra->typioparam;
for (i = 0; i < nitems; i++)
{
value = DatumGetCString(FunctionCall3(&my_extra->proc,
itemvalue,
- ObjectIdGetDatum(typelem),
+ ObjectIdGetDatum(typioparam),
Int32GetDatum(-1)));
if (i > 0)
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/cache/lsyscache.c,v 1.112 2003/12/03 17:45:09 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/cache/lsyscache.c,v 1.113 2004/06/06 00:41:27 tgl Exp $
*
* NOTES
* Eventually, the index information should go through here, too.
ReleaseSysCache(tp);
}
+/*
+ * getTypeIOParam
+ * Given a pg_type row, select the type OID to pass to I/O functions
+ *
+ * Formerly, all I/O functions were passed pg_type.typelem as their second
+ * parameter, but we now have a more complex rule about what to pass.
+ * This knowledge is intended to be centralized here --- direct references
+ * to typelem elsewhere in the code are wrong, if they are associated with
+ * I/O calls and not with actual subscripting operations! (But see
+ * bootstrap.c, which can't conveniently use this routine.)
+ */
+Oid
+getTypeIOParam(HeapTuple typeTuple)
+{
+ Form_pg_type typeStruct = (Form_pg_type) GETSTRUCT(typeTuple);
+
+ /*
+ * Composite types get their own OID as parameter; array types get
+ * their typelem as parameter; everybody else gets zero.
+ */
+ if (typeStruct->typtype == 'c')
+ return HeapTupleGetOid(typeTuple);
+ else
+ return typeStruct->typelem;
+}
+
/*
* get_type_io_data
*
* A six-fer: given the type OID, return typlen, typbyval, typalign,
- * typdelim, typelem, and IO function OID. The IO function
+ * typdelim, typioparam, and IO function OID. The IO function
* returned is controlled by IOFuncSelector
*/
void
bool *typbyval,
char *typalign,
char *typdelim,
- Oid *typelem,
+ Oid *typioparam,
Oid *func)
{
HeapTuple typeTuple;
*typbyval = typeStruct->typbyval;
*typalign = typeStruct->typalign;
*typdelim = typeStruct->typdelim;
- *typelem = typeStruct->typelem;
+ *typioparam = getTypeIOParam(typeTuple);
switch (which_func)
{
case IOFunc_input:
/* Convert C string to a value of the given type */
datum = OidFunctionCall3(type->typinput,
CStringGetDatum(strDefaultVal),
- ObjectIdGetDatum(type->typelem),
+ ObjectIdGetDatum(getTypeIOParam(typeTuple)),
Int32GetDatum(-1));
/* Build a Const node containing the value */
expr = (Node *) makeConst(typid,
* Get info needed for converting values of a type to internal form
*/
void
-getTypeInputInfo(Oid type, Oid *typInput, Oid *typElem)
+getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
{
HeapTuple typeTuple;
Form_pg_type pt;
format_type_be(type))));
*typInput = pt->typinput;
- *typElem = pt->typelem;
+ *typIOParam = getTypeIOParam(typeTuple);
ReleaseSysCache(typeTuple);
}
* Get info needed for printing values of a type
*/
void
-getTypeOutputInfo(Oid type, Oid *typOutput, Oid *typElem,
+getTypeOutputInfo(Oid type, Oid *typOutput, Oid *typIOParam,
bool *typIsVarlena)
{
HeapTuple typeTuple;
format_type_be(type))));
*typOutput = pt->typoutput;
- *typElem = pt->typelem;
+ *typIOParam = getTypeIOParam(typeTuple);
*typIsVarlena = (!pt->typbyval) && (pt->typlen == -1);
ReleaseSysCache(typeTuple);
* Get info needed for binary input of values of a type
*/
void
-getTypeBinaryInputInfo(Oid type, Oid *typReceive, Oid *typElem)
+getTypeBinaryInputInfo(Oid type, Oid *typReceive, Oid *typIOParam)
{
HeapTuple typeTuple;
Form_pg_type pt;
format_type_be(type))));
*typReceive = pt->typreceive;
- *typElem = pt->typelem;
+ *typIOParam = getTypeIOParam(typeTuple);
ReleaseSysCache(typeTuple);
}
* Get info needed for binary output of values of a type
*/
void
-getTypeBinaryOutputInfo(Oid type, Oid *typSend, Oid *typElem,
+getTypeBinaryOutputInfo(Oid type, Oid *typSend, Oid *typIOParam,
bool *typIsVarlena)
{
HeapTuple typeTuple;
format_type_be(type))));
*typSend = pt->typsend;
- *typElem = pt->typelem;
+ *typIOParam = getTypeIOParam(typeTuple);
*typIsVarlena = (!pt->typbyval) && (pt->typlen == -1);
ReleaseSysCache(typeTuple);
*
* Copyright (c) 2002-2003, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/include/funcapi.h,v 1.11 2004/04/01 21:28:46 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/funcapi.h,v 1.12 2004/06/06 00:41:27 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/* array of attribute type input function finfo */
FmgrInfo *attinfuncs;
- /* array of attribute type typelem */
- Oid *attelems;
+ /* array of attribute type i/o parameter OIDs */
+ Oid *attioparams;
/* array of attribute typmod */
int32 *atttypmods;
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/utils/array.h,v 1.46 2003/11/29 22:41:15 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/utils/array.h,v 1.47 2004/06/06 00:41:28 tgl Exp $
*
*-------------------------------------------------------------------------
*/
bool typbyval;
char typalign;
char typdelim;
- Oid typelem;
+ Oid typioparam;
Oid typiofunc;
FmgrInfo proc;
} ArrayMetaState;
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/utils/lsyscache.h,v 1.86 2003/12/03 17:45:10 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/utils/lsyscache.h,v 1.87 2004/06/06 00:41:28 tgl Exp $
*
*-------------------------------------------------------------------------
*/
extern void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval);
extern void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval,
char *typalign);
+extern Oid getTypeIOParam(HeapTuple typeTuple);
extern void get_type_io_data(Oid typid,
IOFuncSelector which_func,
int16 *typlen,
bool *typbyval,
char *typalign,
char *typdelim,
- Oid *typelem,
+ Oid *typioparam,
Oid *func);
extern char get_typstorage(Oid typid);
extern int32 get_typtypmod(Oid typid);
extern Oid get_typ_typrelid(Oid typid);
extern Oid get_element_type(Oid typid);
extern Oid get_array_type(Oid typid);
-extern void getTypeInputInfo(Oid type, Oid *typInput, Oid *typElem);
-extern void getTypeOutputInfo(Oid type, Oid *typOutput, Oid *typElem,
+extern void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam);
+extern void getTypeOutputInfo(Oid type, Oid *typOutput, Oid *typIOParam,
bool *typIsVarlena);
-extern void getTypeBinaryInputInfo(Oid type, Oid *typReceive, Oid *typElem);
-extern void getTypeBinaryOutputInfo(Oid type, Oid *typSend, Oid *typElem,
+extern void getTypeBinaryInputInfo(Oid type, Oid *typReceive, Oid *typIOParam);
+extern void getTypeBinaryOutputInfo(Oid type, Oid *typSend, Oid *typIOParam,
bool *typIsVarlena);
extern Oid getBaseType(Oid typid);
extern int32 get_typavgwidth(Oid typid, int32 typmod);
* ENHANCEMENTS, OR MODIFICATIONS.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.43 2004/04/01 21:28:46 tgl Exp $
+ * $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.44 2004/06/06 00:41:28 tgl Exp $
*
**********************************************************************/
CommandId fn_cmin;
bool lanpltrusted;
FmgrInfo result_in_func;
- Oid result_in_elem;
+ Oid result_typioparam;
int nargs;
FmgrInfo arg_out_func[FUNC_MAX_ARGS];
- Oid arg_out_elem[FUNC_MAX_ARGS];
+ Oid arg_typioparam[FUNC_MAX_ARGS];
bool arg_is_rowtype[FUNC_MAX_ARGS];
SV *reference;
} plperl_proc_desc;
tmp = DatumGetCString(FunctionCall3(&(desc->arg_out_func[i]),
fcinfo->arg[i],
- ObjectIdGetDatum(desc->arg_out_elem[i]),
+ ObjectIdGetDatum(desc->arg_typioparam[i]),
Int32GetDatum(-1)));
XPUSHs(sv_2mortal(newSVpv(tmp, 0)));
pfree(tmp);
{
retval = FunctionCall3(&prodesc->result_in_func,
PointerGetDatum(SvPV(perlret, PL_na)),
- ObjectIdGetDatum(prodesc->result_in_elem),
+ ObjectIdGetDatum(prodesc->result_typioparam),
Int32GetDatum(-1));
}
}
perm_fmgr_info(typeStruct->typinput, &(prodesc->result_in_func));
- prodesc->result_in_elem = typeStruct->typelem;
+ prodesc->result_typioparam = getTypeIOParam(typeTup);
ReleaseSysCache(typeTup);
}
prodesc->arg_is_rowtype[i] = false;
perm_fmgr_info(typeStruct->typoutput,
&(prodesc->arg_out_func[i]));
- prodesc->arg_out_elem[i] = typeStruct->typelem;
+ prodesc->arg_typioparam[i] = getTypeIOParam(typeTup);
}
ReleaseSysCache(typeTup);
char *outputstr;
HeapTuple typeTup;
Oid typoutput;
- Oid typelem;
+ Oid typioparam;
output = sv_2mortal(newSVpv("{", 0));
tupdesc->attrs[i]->atttypid);
typoutput = ((Form_pg_type) GETSTRUCT(typeTup))->typoutput;
- typelem = ((Form_pg_type) GETSTRUCT(typeTup))->typelem;
+ typioparam = getTypeIOParam(typeTup);
ReleaseSysCache(typeTup);
/************************************************************
************************************************************/
outputstr = DatumGetCString(OidFunctionCall3(typoutput,
attr,
- ObjectIdGetDatum(typelem),
+ ObjectIdGetDatum(typioparam),
Int32GetDatum(tupdesc->attrs[i]->atttypmod)));
sv_catpvf(output, "'%s' => '%s',", attname, outputstr);
pfree(outputstr);
* procedural language
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.76 2004/06/03 22:56:43 tgl Exp $
+ * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.77 2004/06/06 00:41:28 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
{
function->fn_retbyval = typeStruct->typbyval;
function->fn_rettyplen = typeStruct->typlen;
- function->fn_rettypelem = typeStruct->typelem;
+ function->fn_rettypioparam = getTypeIOParam(typeTup);
perm_fmgr_info(typeStruct->typinput, &(function->fn_retinput));
/*
typ->typlen = typeStruct->typlen;
typ->typbyval = typeStruct->typbyval;
typ->typrelid = typeStruct->typrelid;
- typ->typelem = typeStruct->typelem;
+ typ->typioparam = getTypeIOParam(typeTup);
perm_fmgr_info(typeStruct->typinput, &(typ->typinput));
typ->atttypmod = typmod;
* procedural language
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.105 2004/06/05 19:48:09 tgl Exp $
+ * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.106 2004/06/06 00:41:28 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
static Datum exec_cast_value(Datum value, Oid valtype,
Oid reqtype,
FmgrInfo *reqinput,
- Oid reqtypelem,
+ Oid reqtypioparam,
int32 reqtypmod,
bool *isnull);
static Datum exec_simple_cast_value(Datum value, Oid valtype,
estate.retval = exec_cast_value(estate.retval, estate.rettype,
func->fn_rettype,
&(func->fn_retinput),
- func->fn_rettypelem,
+ func->fn_rettypioparam,
-1,
&fcinfo->isnull);
value = exec_eval_expr(estate, stmt->lower, &isnull, &valtype);
value = exec_cast_value(value, valtype, var->datatype->typoid,
&(var->datatype->typinput),
- var->datatype->typelem,
+ var->datatype->typioparam,
var->datatype->atttypmod, &isnull);
if (isnull)
ereport(ERROR,
value = exec_eval_expr(estate, stmt->upper, &isnull, &valtype);
value = exec_cast_value(value, valtype, var->datatype->typoid,
&(var->datatype->typinput),
- var->datatype->typelem,
+ var->datatype->typioparam,
var->datatype->atttypmod, &isnull);
if (isnull)
ereport(ERROR,
newvalue = exec_cast_value(value, valtype, var->datatype->typoid,
&(var->datatype->typinput),
- var->datatype->typelem,
+ var->datatype->typioparam,
var->datatype->atttypmod,
isNull);
bool havenullsubscript,
oldarrayisnull;
Oid arraytypeid,
- arrayelemtypeid,
- arrayInputFn;
+ arrayelemtypeid;
int16 elemtyplen;
bool elemtypbyval;
char elemtypalign;
exec_eval_datum(estate, target, InvalidOid,
&arraytypeid, &oldarrayval, &oldarrayisnull);
- getTypeInputInfo(arraytypeid, &arrayInputFn, &arrayelemtypeid);
+ arrayelemtypeid = get_element_type(arraytypeid);
if (!OidIsValid(arrayelemtypeid))
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
static char *
convert_value_to_string(Datum value, Oid valtype)
{
- Oid typOutput;
- Oid typElem;
+ Oid typoutput;
+ Oid typioparam;
bool typIsVarlena;
- FmgrInfo finfo_output;
- getTypeOutputInfo(valtype, &typOutput, &typElem, &typIsVarlena);
+ getTypeOutputInfo(valtype, &typoutput, &typioparam, &typIsVarlena);
- fmgr_info(typOutput, &finfo_output);
-
- return DatumGetCString(FunctionCall3(&finfo_output,
- value,
- ObjectIdGetDatum(typElem),
- Int32GetDatum(-1)));
+ return DatumGetCString(OidFunctionCall3(typoutput,
+ value,
+ ObjectIdGetDatum(typioparam),
+ Int32GetDatum(-1)));
}
/* ----------
exec_cast_value(Datum value, Oid valtype,
Oid reqtype,
FmgrInfo *reqinput,
- Oid reqtypelem,
+ Oid reqtypioparam,
int32 reqtypmod,
bool *isnull)
{
extval = convert_value_to_string(value, valtype);
value = FunctionCall3(reqinput,
CStringGetDatum(extval),
- ObjectIdGetDatum(reqtypelem),
+ ObjectIdGetDatum(reqtypioparam),
Int32GetDatum(reqtypmod));
pfree(extval);
}
{
if (valtype != reqtype || reqtypmod != -1)
{
- Oid typInput;
- Oid typElem;
+ Oid typinput;
+ Oid typioparam;
FmgrInfo finfo_input;
- getTypeInputInfo(reqtype, &typInput, &typElem);
+ getTypeInputInfo(reqtype, &typinput, &typioparam);
- fmgr_info(typInput, &finfo_input);
+ fmgr_info(typinput, &finfo_input);
value = exec_cast_value(value,
valtype,
reqtype,
&finfo_input,
- typElem,
+ typioparam,
reqtypmod,
isnull);
}
* procedural language
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.46 2004/06/03 22:56:43 tgl Exp $
+ * $PostgreSQL: pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.47 2004/06/06 00:41:28 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
int16 typlen; /* stuff copied from its pg_type entry */
bool typbyval;
Oid typrelid;
- Oid typelem;
+ Oid typioparam;
FmgrInfo typinput; /* lookup info for typinput function */
int32 atttypmod; /* typmod (taken from someplace else) */
} PLpgSQL_type;
int fn_rettyplen;
bool fn_retbyval;
FmgrInfo fn_retinput;
- Oid fn_rettypelem;
+ Oid fn_rettypioparam;
bool fn_retistuple;
bool fn_retset;
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.48 2004/06/05 19:48:09 tgl Exp $
+ * $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.49 2004/06/06 00:41:28 tgl Exp $
*
*********************************************************************
*/
#include "nodes/makefuncs.h"
#include "parser/parse_type.h"
#include "tcop/tcopprot.h"
+#include "utils/lsyscache.h"
#include "utils/syscache.h"
#include "utils/typcache.h"
{
PLyDatumToObFunc func;
FmgrInfo typfunc;
- Oid typelem;
+ Oid typioparam;
bool typbyval;
} PLyDatumToOb;
typedef struct PLyObToDatum
{
FmgrInfo typfunc;
- Oid typelem;
+ Oid typioparam;
bool typbyval;
} PLyObToDatum;
static void PLy_typeinfo_init(PLyTypeInfo *);
static void PLy_typeinfo_dealloc(PLyTypeInfo *);
-static void PLy_output_datum_func(PLyTypeInfo *, Form_pg_type);
-static void PLy_output_datum_func2(PLyObToDatum *, Form_pg_type);
-static void PLy_input_datum_func(PLyTypeInfo *, Oid, Form_pg_type);
-static void PLy_input_datum_func2(PLyDatumToOb *, Oid, Form_pg_type);
+static void PLy_output_datum_func(PLyTypeInfo *, HeapTuple);
+static void PLy_output_datum_func2(PLyObToDatum *, HeapTuple);
+static void PLy_input_datum_func(PLyTypeInfo *, Oid, HeapTuple);
+static void PLy_input_datum_func2(PLyDatumToOb *, Oid, HeapTuple);
static void PLy_output_tuple_funcs(PLyTypeInfo *, TupleDesc);
static void PLy_input_tuple_funcs(PLyTypeInfo *, TupleDesc);
modvalues[i] = FunctionCall3(&proc->result.out.r.atts[atti].typfunc,
CStringGetDatum(src),
- ObjectIdGetDatum(proc->result.out.r.atts[atti].typelem),
+ ObjectIdGetDatum(proc->result.out.r.atts[atti].typioparam),
Int32GetDatum(tupdesc->attrs[atti]->atttypmod));
modnulls[i] = ' ';
plrv_sc = PyString_AsString(plrv_so);
rv = FunctionCall3(&proc->result.out.d.typfunc,
PointerGetDatum(plrv_sc),
- ObjectIdGetDatum(proc->result.out.d.typelem),
+ ObjectIdGetDatum(proc->result.out.d.typioparam),
Int32GetDatum(-1));
}
dt = FunctionCall3(&(proc->args[i].in.d.typfunc),
fcinfo->arg[i],
- ObjectIdGetDatum(proc->args[i].in.d.typelem),
+ ObjectIdGetDatum(proc->args[i].in.d.typioparam),
Int32GetDatum(-1));
ct = DatumGetCString(dt);
arg = (proc->args[i].in.d.func) (ct);
rvTypeStruct = (Form_pg_type) GETSTRUCT(rvTypeTup);
if (rvTypeStruct->typtype != 'c')
- PLy_output_datum_func(&proc->result, rvTypeStruct);
+ PLy_output_datum_func(&proc->result, rvTypeTup);
else
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
if (argTypeStruct->typtype != 'c')
PLy_input_datum_func(&(proc->args[i]),
procStruct->proargtypes[i],
- argTypeStruct);
+ argTypeTup);
else
proc->args[i].is_rowtype = 2; /* still need to set I/O funcs */
for (i = 0; i < desc->natts; i++)
{
HeapTuple typeTup;
- Form_pg_type typeStruct;
if (desc->attrs[i]->attisdropped)
continue;
if (!HeapTupleIsValid(typeTup))
elog(ERROR, "cache lookup failed for type %u",
desc->attrs[i]->atttypid);
- typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
PLy_input_datum_func2(&(arg->in.r.atts[i]),
desc->attrs[i]->atttypid,
- typeStruct);
+ typeTup);
ReleaseSysCache(typeTup);
}
for (i = 0; i < desc->natts; i++)
{
HeapTuple typeTup;
- Form_pg_type typeStruct;
if (desc->attrs[i]->attisdropped)
continue;
if (!HeapTupleIsValid(typeTup))
elog(ERROR, "cache lookup failed for type %u",
desc->attrs[i]->atttypid);
- typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
- PLy_output_datum_func2(&(arg->out.r.atts[i]), typeStruct);
+ PLy_output_datum_func2(&(arg->out.r.atts[i]), typeTup);
ReleaseSysCache(typeTup);
}
}
void
-PLy_output_datum_func(PLyTypeInfo * arg, Form_pg_type typeStruct)
+PLy_output_datum_func(PLyTypeInfo * arg, HeapTuple typeTup)
{
enter();
if (arg->is_rowtype > 0)
elog(ERROR, "PLyTypeInfo struct is initialized for a Tuple");
arg->is_rowtype = 0;
- PLy_output_datum_func2(&(arg->out.d), typeStruct);
+ PLy_output_datum_func2(&(arg->out.d), typeTup);
}
void
-PLy_output_datum_func2(PLyObToDatum * arg, Form_pg_type typeStruct)
+PLy_output_datum_func2(PLyObToDatum * arg, HeapTuple typeTup)
{
+ Form_pg_type typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
+
enter();
perm_fmgr_info(typeStruct->typinput, &arg->typfunc);
- arg->typelem = typeStruct->typelem;
+ arg->typioparam = getTypeIOParam(typeTup);
arg->typbyval = typeStruct->typbyval;
}
void
-PLy_input_datum_func(PLyTypeInfo * arg, Oid typeOid, Form_pg_type typeStruct)
+PLy_input_datum_func(PLyTypeInfo * arg, Oid typeOid, HeapTuple typeTup)
{
enter();
if (arg->is_rowtype > 0)
elog(ERROR, "PLyTypeInfo struct is initialized for Tuple");
arg->is_rowtype = 0;
- PLy_input_datum_func2(&(arg->in.d), typeOid, typeStruct);
+ PLy_input_datum_func2(&(arg->in.d), typeOid, typeTup);
}
void
-PLy_input_datum_func2(PLyDatumToOb * arg, Oid typeOid, Form_pg_type typeStruct)
+PLy_input_datum_func2(PLyDatumToOb * arg, Oid typeOid, HeapTuple typeTup)
{
+ Form_pg_type typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
+
/* Get the type's conversion information */
perm_fmgr_info(typeStruct->typoutput, &arg->typfunc);
- arg->typelem = typeStruct->typelem;
+ arg->typioparam = getTypeIOParam(typeTup);
arg->typbyval = typeStruct->typbyval;
/* Determine which kind of Python object we will convert to */
{
vdat = FunctionCall3(&info->in.r.atts[i].typfunc,
vattr,
- ObjectIdGetDatum(info->in.r.atts[i].typelem),
+ ObjectIdGetDatum(info->in.r.atts[i].typioparam),
Int32GetDatum(desc->attrs[i]->atttypmod));
vsrc = DatumGetCString(vdat);
plan->types[i] = HeapTupleGetOid(typeTup);
typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
if (typeStruct->typtype != 'c')
- PLy_output_datum_func(&plan->args[i], typeStruct);
+ PLy_output_datum_func(&plan->args[i], typeTup);
else
{
PyErr_SetString(PLy_exc_spi_error,
plan->values[i] =
FunctionCall3(&(plan->args[i].out.d.typfunc),
CStringGetDatum(sv),
- ObjectIdGetDatum(plan->args[i].out.d.typelem),
+ ObjectIdGetDatum(plan->args[i].out.d.typioparam),
Int32GetDatum(-1));
Py_DECREF(so);
* ENHANCEMENTS, OR MODIFICATIONS.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/pl/tcl/pltcl.c,v 1.85 2004/05/30 23:40:41 neilc Exp $
+ * $PostgreSQL: pgsql/src/pl/tcl/pltcl.c,v 1.86 2004/06/06 00:41:28 tgl Exp $
*
**********************************************************************/
#include "access/heapam.h"
#include "catalog/pg_language.h"
#include "catalog/pg_proc.h"
-#include "catalog/pg_type.h"
#include "commands/trigger.h"
#include "executor/spi.h"
#include "fmgr.h"
#include "parser/parse_type.h"
#include "tcop/tcopprot.h"
#include "utils/builtins.h"
+#include "utils/lsyscache.h"
#include "utils/syscache.h"
#include "utils/typcache.h"
CommandId fn_cmin;
bool lanpltrusted;
FmgrInfo result_in_func;
- Oid result_in_elem;
+ Oid result_typioparam;
int nargs;
FmgrInfo arg_out_func[FUNC_MAX_ARGS];
- Oid arg_out_elem[FUNC_MAX_ARGS];
+ Oid arg_typioparam[FUNC_MAX_ARGS];
bool arg_is_rowtype[FUNC_MAX_ARGS];
} pltcl_proc_desc;
int nargs;
Oid *argtypes;
FmgrInfo *arginfuncs;
- Oid *argtypelems;
+ Oid *argtypioparams;
} pltcl_query_desc;
tmp = DatumGetCString(FunctionCall3(&prodesc->arg_out_func[i],
fcinfo->arg[i],
- ObjectIdGetDatum(prodesc->arg_out_elem[i]),
+ ObjectIdGetDatum(prodesc->arg_typioparam[i]),
Int32GetDatum(-1)));
UTF_BEGIN;
Tcl_DStringAppendElement(&tcl_cmd, UTF_E2U(tmp));
UTF_BEGIN;
retval = FunctionCall3(&prodesc->result_in_func,
PointerGetDatum(UTF_U2E(interp->result)),
- ObjectIdGetDatum(prodesc->result_in_elem),
+ ObjectIdGetDatum(prodesc->result_typioparam),
Int32GetDatum(-1));
UTF_END;
}
int attnum;
HeapTuple typeTup;
Oid typinput;
- Oid typelem;
+ Oid typioparam;
FmgrInfo finfo;
/************************************************************
elog(ERROR, "cache lookup failed for type %u",
tupdesc->attrs[attnum - 1]->atttypid);
typinput = ((Form_pg_type) GETSTRUCT(typeTup))->typinput;
- typelem = ((Form_pg_type) GETSTRUCT(typeTup))->typelem;
+ typioparam = getTypeIOParam(typeTup);
ReleaseSysCache(typeTup);
/************************************************************
modvalues[attnum - 1] =
FunctionCall3(&finfo,
CStringGetDatum(UTF_U2E(ret_value)),
- ObjectIdGetDatum(typelem),
+ ObjectIdGetDatum(typioparam),
Int32GetDatum(tupdesc->attrs[attnum - 1]->atttypmod));
UTF_END;
}
}
perm_fmgr_info(typeStruct->typinput, &(prodesc->result_in_func));
- prodesc->result_in_elem = typeStruct->typelem;
+ prodesc->result_typioparam = getTypeIOParam(typeTup);
ReleaseSysCache(typeTup);
}
prodesc->arg_is_rowtype[i] = false;
perm_fmgr_info(typeStruct->typoutput,
&(prodesc->arg_out_func[i]));
- prodesc->arg_out_elem[i] = typeStruct->typelem;
+ prodesc->arg_typioparam[i] = getTypeIOParam(typeTup);
snprintf(buf, sizeof(buf), "%d", i + 1);
}
qdesc->nargs = nargs;
qdesc->argtypes = (Oid *) malloc(nargs * sizeof(Oid));
qdesc->arginfuncs = (FmgrInfo *) malloc(nargs * sizeof(FmgrInfo));
- qdesc->argtypelems = (Oid *) malloc(nargs * sizeof(Oid));
+ qdesc->argtypioparams = (Oid *) malloc(nargs * sizeof(Oid));
/************************************************************
* Prepare to start a controlled return through all
pltcl_restart_in_progress = 1;
free(qdesc->argtypes);
free(qdesc->arginfuncs);
- free(qdesc->argtypelems);
+ free(qdesc->argtypioparams);
free(qdesc);
ckfree((char *) args);
return TCL_ERROR;
qdesc->argtypes[i] = HeapTupleGetOid(typeTup);
perm_fmgr_info(((Form_pg_type) GETSTRUCT(typeTup))->typinput,
&(qdesc->arginfuncs[i]));
- qdesc->argtypelems[i] = ((Form_pg_type) GETSTRUCT(typeTup))->typelem;
+ qdesc->argtypioparams[i] = getTypeIOParam(typeTup);
ReleaseSysCache(typeTup);
list_free(typename->names);
argvalues[j] =
FunctionCall3(&qdesc->arginfuncs[j],
CStringGetDatum(UTF_U2E(callargs[j])),
- ObjectIdGetDatum(qdesc->argtypelems[j]),
+ ObjectIdGetDatum(qdesc->argtypioparams[j]),
Int32GetDatum(-1));
UTF_END;
}
CONST84 char *attname;
HeapTuple typeTup;
Oid typoutput;
- Oid typelem;
+ Oid typioparam;
CONST84 char **arrptr;
CONST84 char **nameptr;
tupdesc->attrs[i]->atttypid);
typoutput = ((Form_pg_type) GETSTRUCT(typeTup))->typoutput;
- typelem = ((Form_pg_type) GETSTRUCT(typeTup))->typelem;
+ typioparam = getTypeIOParam(typeTup);
ReleaseSysCache(typeTup);
/************************************************************
{
outputstr = DatumGetCString(OidFunctionCall3(typoutput,
attr,
- ObjectIdGetDatum(typelem),
+ ObjectIdGetDatum(typioparam),
Int32GetDatum(tupdesc->attrs[i]->atttypmod)));
UTF_BEGIN;
Tcl_SetVar2(interp, *arrptr, *nameptr, UTF_E2U(outputstr), 0);
char *attname;
HeapTuple typeTup;
Oid typoutput;
- Oid typelem;
+ Oid typioparam;
for (i = 0; i < tupdesc->natts; i++)
{
tupdesc->attrs[i]->atttypid);
typoutput = ((Form_pg_type) GETSTRUCT(typeTup))->typoutput;
- typelem = ((Form_pg_type) GETSTRUCT(typeTup))->typelem;
+ typioparam = getTypeIOParam(typeTup);
ReleaseSysCache(typeTup);
/************************************************************
{
outputstr = DatumGetCString(OidFunctionCall3(typoutput,
attr,
- ObjectIdGetDatum(typelem),
+ ObjectIdGetDatum(typioparam),
Int32GetDatum(tupdesc->attrs[i]->atttypmod)));
Tcl_DStringAppendElement(retval, attname);
UTF_BEGIN;