Skip to content

Commit afc7e0d

Browse files
committed
Allow pltcl args to spi_prepare and plpython args to plpy.prepare to be standard type aliases as well as those known in pg_type. Similar to recent change in plperl.
1 parent 80ab3e0 commit afc7e0d

File tree

3 files changed

+32
-29
lines changed

3 files changed

+32
-29
lines changed

doc/src/sgml/pltcl.sgml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/pltcl.sgml,v 2.45 2007/02/01 00:28:17 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/pltcl.sgml,v 2.46 2007/02/21 03:27:31 adunstan Exp $ -->
22

33
<chapter id="pltcl">
44
<title>PL/Tcl - Tcl Procedural Language</title>
@@ -331,9 +331,6 @@ spi_exec -array C "SELECT * FROM pg_class" {
331331
If the query uses parameters, the names of the parameter types
332332
must be given as a Tcl list. (Write an empty list for
333333
<replaceable>typelist</replaceable> if no parameters are used.)
334-
Presently, the parameter types must be identified by the internal
335-
type names shown in the system table <literal>pg_type</>; for example <literal>int4</> not
336-
<literal>integer</>.
337334
</para>
338335
<para>
339336
The return value from <function>spi_prepare</function> is a query ID

src/pl/plpython/plpython.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**********************************************************************
22
* plpython.c - python as a procedural language for PostgreSQL
33
*
4-
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.95 2007/02/09 03:35:35 tgl Exp $
4+
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.96 2007/02/21 03:27:32 adunstan Exp $
55
*
66
*********************************************************************
77
*/
@@ -2309,27 +2309,34 @@ PLy_spi_prepare(PyObject * self, PyObject * args)
23092309
for (i = 0; i < nargs; i++)
23102310
{
23112311
char *sptr;
2312-
List *names;
23132312
HeapTuple typeTup;
2313+
Oid typeId;
2314+
int32 typmod;
23142315
Form_pg_type typeStruct;
23152316

23162317
optr = PySequence_GetItem(list, i);
23172318
if (!PyString_Check(optr))
23182319
elog(ERROR, "Type names must be strings.");
23192320
sptr = PyString_AsString(optr);
2321+
2322+
/********************************************************
2323+
* Resolve argument type names and then look them up by
2324+
* oid in the system cache, and remember the required
2325+
*information for input conversion.
2326+
********************************************************/
2327+
2328+
parseTypeString(sptr, &typeId, &typmod);
2329+
2330+
typeTup = SearchSysCache(TYPEOID,
2331+
ObjectIdGetDatum(typeId),
2332+
0,0,0);
2333+
if (!HeapTupleIsValid(typeTup))
2334+
elog(ERROR, "cache lookup failed for type %u", typeId);
23202335

2321-
/*
2322-
* Parse possibly-qualified type name and look it up in
2323-
* pg_type
2324-
*/
2325-
names = stringToQualifiedNameList(sptr,
2326-
"PLy_spi_prepare");
2327-
typeTup = typenameType(NULL,
2328-
makeTypeNameFromNameList(names));
23292336
Py_DECREF(optr);
23302337
optr = NULL; /* this is important */
23312338

2332-
plan->types[i] = HeapTupleGetOid(typeTup);
2339+
plan->types[i] = typeId;
23332340
typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
23342341
if (typeStruct->typtype != 'c')
23352342
PLy_output_datum_func(&plan->args[i], typeTup);

src/pl/tcl/pltcl.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* pltcl.c - PostgreSQL support for Tcl as
33
* procedural language (PL)
44
*
5-
* $PostgreSQL: pgsql/src/pl/tcl/pltcl.c,v 1.110 2007/02/09 03:35:35 tgl Exp $
5+
* $PostgreSQL: pgsql/src/pl/tcl/pltcl.c,v 1.111 2007/02/21 03:27:32 adunstan Exp $
66
*
77
**********************************************************************/
88

@@ -1808,23 +1808,22 @@ pltcl_SPI_prepare(ClientData cdata, Tcl_Interp *interp,
18081808
PG_TRY();
18091809
{
18101810
/************************************************************
1811-
* Lookup the argument types by name in the system cache
1812-
* and remember the required information for input conversion
1811+
* Resolve argument type names and then look them up by oid
1812+
* in the system cache, and remember the required information
1813+
* for input conversion.
18131814
************************************************************/
18141815
for (i = 0; i < nargs; i++)
18151816
{
1816-
List *names;
1817-
HeapTuple typeTup;
1817+
Oid typId, typInput, typIOParam;
1818+
int32 typmod;
18181819

1819-
/* Parse possibly-qualified type name and look it up in pg_type */
1820-
names = stringToQualifiedNameList(args[i],
1821-
"pltcl_SPI_prepare");
1822-
typeTup = typenameType(NULL, makeTypeNameFromNameList(names));
1823-
qdesc->argtypes[i] = HeapTupleGetOid(typeTup);
1824-
perm_fmgr_info(((Form_pg_type) GETSTRUCT(typeTup))->typinput,
1825-
&(qdesc->arginfuncs[i]));
1826-
qdesc->argtypioparams[i] = getTypeIOParam(typeTup);
1827-
ReleaseSysCache(typeTup);
1820+
parseTypeString(args[i], &typId, &typmod);
1821+
1822+
getTypeInputInfo(typId, &typInput, &typIOParam);
1823+
1824+
qdesc->argtypes[i] = typId;
1825+
perm_fmgr_info(typInput, &(qdesc->arginfuncs[i]));
1826+
qdesc->argtypioparams[i] = typIOParam;
18281827
}
18291828

18301829
/************************************************************

0 commit comments

Comments
 (0)