1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Add a bunch of pseudo-types to replace the behavior formerly associated

with OPAQUE, as per recent pghackers discussion.  I still want to do some
more work on the 'cstring' pseudo-type, but I'm going to commit the bulk
of the changes now before the tree starts shifting under me ...
This commit is contained in:
Tom Lane
2002-08-22 00:01:51 +00:00
parent 606c9b9d4f
commit b663f3443b
126 changed files with 2005 additions and 1205 deletions

View File

@@ -33,7 +33,7 @@
* ENHANCEMENTS, OR MODIFICATIONS.
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/plperl/plperl.c,v 1.31 2002/06/15 19:54:24 momjian Exp $
* $Header: /cvsroot/pgsql/src/pl/plperl/plperl.c,v 1.32 2002/08/22 00:01:49 tgl Exp $
*
**********************************************************************/
@@ -619,15 +619,34 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
{
free(prodesc->proname);
free(prodesc);
if (!OidIsValid(procStruct->prorettype))
elog(ERROR, "plperl functions cannot return type \"opaque\""
"\n\texcept when used as triggers");
else
elog(ERROR, "plperl: cache lookup for return type %u failed",
procStruct->prorettype);
elog(ERROR, "plperl: cache lookup for return type %u failed",
procStruct->prorettype);
}
typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
/* Disallow pseudotype result, except VOID */
if (typeStruct->typtype == 'p')
{
if (procStruct->prorettype == VOIDOID)
/* okay */;
else if (procStruct->prorettype == TRIGGEROID ||
procStruct->prorettype == OPAQUEOID)
{
free(prodesc->proname);
free(prodesc);
elog(ERROR, "plperl functions cannot return type %s"
"\n\texcept when used as triggers",
format_type_be(procStruct->prorettype));
}
else
{
free(prodesc->proname);
free(prodesc);
elog(ERROR, "plperl functions cannot return type %s",
format_type_be(procStruct->prorettype));
}
}
if (typeStruct->typrelid != InvalidOid)
{
free(prodesc->proname);
@@ -657,14 +676,20 @@ compile_plperl_function(Oid fn_oid, bool is_trigger)
{
free(prodesc->proname);
free(prodesc);
if (!OidIsValid(procStruct->proargtypes[i]))
elog(ERROR, "plperl functions cannot take type \"opaque\"");
else
elog(ERROR, "plperl: cache lookup for argument type %u failed",
procStruct->proargtypes[i]);
elog(ERROR, "plperl: cache lookup for argument type %u failed",
procStruct->proargtypes[i]);
}
typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
/* Disallow pseudotype argument */
if (typeStruct->typtype == 'p')
{
free(prodesc->proname);
free(prodesc);
elog(ERROR, "plperl functions cannot take type %s",
format_type_be(procStruct->proargtypes[i]));
}
if (typeStruct->typrelid != InvalidOid)
prodesc->arg_is_rel[i] = 1;
else

View File

@@ -3,7 +3,7 @@
* procedural language
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.46 2002/08/15 16:36:08 momjian Exp $
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.47 2002/08/22 00:01:50 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
@@ -212,15 +212,25 @@ plpgsql_compile(Oid fn_oid, int functype)
ObjectIdGetDatum(procStruct->prorettype),
0, 0, 0);
if (!HeapTupleIsValid(typeTup))
{
if (!OidIsValid(procStruct->prorettype))
elog(ERROR, "plpgsql functions cannot return type \"opaque\""
"\n\texcept when used as triggers");
else
elog(ERROR, "cache lookup for return type %u failed",
procStruct->prorettype);
}
elog(ERROR, "cache lookup for return type %u failed",
procStruct->prorettype);
typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
/* Disallow pseudotype result, except VOID */
if (typeStruct->typtype == 'p')
{
if (procStruct->prorettype == VOIDOID)
/* okay */;
else if (procStruct->prorettype == TRIGGEROID ||
procStruct->prorettype == OPAQUEOID)
elog(ERROR, "plpgsql functions cannot return type %s"
"\n\texcept when used as triggers",
format_type_be(procStruct->prorettype));
else
elog(ERROR, "plpgsql functions cannot return type %s",
format_type_be(procStruct->prorettype));
}
if (typeStruct->typrelid != InvalidOid)
function->fn_retistuple = true;
else
@@ -248,15 +258,15 @@ plpgsql_compile(Oid fn_oid, int functype)
ObjectIdGetDatum(procStruct->proargtypes[i]),
0, 0, 0);
if (!HeapTupleIsValid(typeTup))
{
if (!OidIsValid(procStruct->proargtypes[i]))
elog(ERROR, "plpgsql functions cannot take type \"opaque\"");
else
elog(ERROR, "cache lookup for argument type %u failed",
procStruct->proargtypes[i]);
}
elog(ERROR, "cache lookup for argument type %u failed",
procStruct->proargtypes[i]);
typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
/* Disallow pseudotype argument */
if (typeStruct->typtype == 'p')
elog(ERROR, "plpgsql functions cannot take type %s",
format_type_be(procStruct->proargtypes[i]));
if (typeStruct->typrelid != InvalidOid)
{
/*

View File

@@ -29,7 +29,7 @@
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.19 2002/07/20 05:16:59 momjian Exp $
* $Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.20 2002/08/22 00:01:50 tgl Exp $
*
*********************************************************************
*/
@@ -447,7 +447,7 @@ plpython_call_handler(PG_FUNCTION_ARGS)
* this action. MODIFY means the tuple has been modified, so update
* tuple and perform action. SKIP and MODIFY assume the trigger fires
* BEFORE the event and is ROW level. postgres expects the function
* to take no arguments and return an argument of type opaque.
* to take no arguments and return an argument of type trigger.
*/
HeapTuple
PLy_trigger_handler(FunctionCallInfo fcinfo, PLyProcedure * proc)

View File

@@ -92,7 +92,7 @@ return words'
-- vigorously resisted all efforts at correction. they have
-- since gone bankrupt...
CREATE FUNCTION users_insert() returns opaque
CREATE FUNCTION users_insert() returns trigger
AS
'if TD["new"]["fname"] == None or TD["new"]["lname"] == None:
return "SKIP"
@@ -108,7 +108,7 @@ return rv'
LANGUAGE 'plpython';
CREATE FUNCTION users_update() returns opaque
CREATE FUNCTION users_update() returns trigger
AS
'if TD["event"] == "UPDATE":
if TD["old"]["fname"] != TD["new"]["fname"] and TD["old"]["fname"] == TD["args"][0]:
@@ -117,7 +117,7 @@ return None'
LANGUAGE 'plpython';
CREATE FUNCTION users_delete() RETURNS opaque
CREATE FUNCTION users_delete() RETURNS trigger
AS
'if TD["old"]["fname"] == TD["args"][0]:
return "SKIP"

View File

@@ -31,7 +31,7 @@
* ENHANCEMENTS, OR MODIFICATIONS.
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.59 2002/07/20 05:16:59 momjian Exp $
* $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.60 2002/08/22 00:01:50 tgl Exp $
*
**********************************************************************/
@@ -1051,15 +1051,34 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger)
{
free(prodesc->proname);
free(prodesc);
if (!OidIsValid(procStruct->prorettype))
elog(ERROR, "pltcl functions cannot return type \"opaque\""
"\n\texcept when used as triggers");
else
elog(ERROR, "pltcl: cache lookup for return type %u failed",
procStruct->prorettype);
elog(ERROR, "pltcl: cache lookup for return type %u failed",
procStruct->prorettype);
}
typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
/* Disallow pseudotype result, except VOID */
if (typeStruct->typtype == 'p')
{
if (procStruct->prorettype == VOIDOID)
/* okay */;
else if (procStruct->prorettype == TRIGGEROID ||
procStruct->prorettype == OPAQUEOID)
{
free(prodesc->proname);
free(prodesc);
elog(ERROR, "pltcl functions cannot return type %s"
"\n\texcept when used as triggers",
format_type_be(procStruct->prorettype));
}
else
{
free(prodesc->proname);
free(prodesc);
elog(ERROR, "pltcl functions cannot return type %s",
format_type_be(procStruct->prorettype));
}
}
if (typeStruct->typrelid != InvalidOid)
{
free(prodesc->proname);
@@ -1090,14 +1109,20 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger)
{
free(prodesc->proname);
free(prodesc);
if (!OidIsValid(procStruct->proargtypes[i]))
elog(ERROR, "pltcl functions cannot take type \"opaque\"");
else
elog(ERROR, "pltcl: cache lookup for argument type %u failed",
procStruct->proargtypes[i]);
elog(ERROR, "pltcl: cache lookup for argument type %u failed",
procStruct->proargtypes[i]);
}
typeStruct = (Form_pg_type) GETSTRUCT(typeTup);
/* Disallow pseudotype argument */
if (typeStruct->typtype == 'p')
{
free(prodesc->proname);
free(prodesc);
elog(ERROR, "pltcl functions cannot take type %s",
format_type_be(procStruct->proargtypes[i]));
}
if (typeStruct->typrelid != InvalidOid)
{
prodesc->arg_is_rel[i] = 1;

View File

@@ -58,7 +58,7 @@ create function check_pkey1_exists(int4, bpchar) returns bool as '
--
-- Trigger function on every change to T_pkey1
--
create function trig_pkey1_before() returns opaque as '
create function trig_pkey1_before() returns trigger as '
#
# Create prepared plans on the first call
#
@@ -152,7 +152,7 @@ create trigger pkey1_before before insert or update or delete on T_pkey1
-- Trigger function to check for duplicate keys in T_pkey2
-- and to force key2 to be upper case only without leading whitespaces
--
create function trig_pkey2_before() returns opaque as '
create function trig_pkey2_before() returns trigger as '
#
# Prepare plan on first call
#
@@ -195,7 +195,7 @@ create trigger pkey2_before before insert or update on T_pkey2
-- in T_pkey2 are done so the trigger for primkey check on T_dta2
-- fired on our updates will see the new key values in T_pkey2.
--
create function trig_pkey2_after() returns opaque as '
create function trig_pkey2_after() returns trigger as '
#
# Prepare plans on first call
#
@@ -282,7 +282,7 @@ create trigger pkey2_after after update or delete on T_pkey2
--
-- Generic trigger function to check references in T_dta1 and T_dta2
--
create function check_primkey() returns opaque as '
create function check_primkey() returns trigger as '
#
# For every trigger/relation pair we create
# a saved plan and hold them in GD