polymorphism.out
来自「postgresql8.3.4源码,开源数据库」· OUT 代码 · 共 616 行 · 第 1/2 页
OUT
616 行
-- Currently this tests polymorphic aggregates and indirectly does some-- testing of polymorphic SQL functions. It ought to be extended.-- Legend:------------- A = type is ANY-- P = type is polymorphic-- N = type is non-polymorphic-- B = aggregate base type-- S = aggregate state type-- R = aggregate return type-- 1 = arg1 of a function-- 2 = arg2 of a function-- ag = aggregate-- tf = trans (state) function-- ff = final function-- rt = return type of a function-- -> = implies-- => = allowed-- !> = not allowed-- E = exists-- NE = not-exists-- -- Possible states:-- ------------------ B = (A || P || N)-- when (B = A) -> (tf2 = NE)-- S = (P || N)-- ff = (E || NE)-- tf1 = (P || N)-- tf2 = (NE || P || N)-- R = (P || N)-- create functions for use as tf and ff with the needed combinations of-- argument polymorphism, but within the constraints of valid aggregate-- functions, i.e. tf arg1 and tf return type must match-- polymorphic single arg transfnCREATE FUNCTION stfp(anyarray) RETURNS anyarray AS'select $1' LANGUAGE SQL;-- non-polymorphic single arg transfnCREATE FUNCTION stfnp(int[]) RETURNS int[] AS'select $1' LANGUAGE SQL;-- dual polymorphic transfnCREATE FUNCTION tfp(anyarray,anyelement) RETURNS anyarray AS'select $1 || $2' LANGUAGE SQL;-- dual non-polymorphic transfnCREATE FUNCTION tfnp(int[],int) RETURNS int[] AS'select $1 || $2' LANGUAGE SQL;-- arg1 only polymorphic transfnCREATE FUNCTION tf1p(anyarray,int) RETURNS anyarray AS'select $1' LANGUAGE SQL;-- arg2 only polymorphic transfnCREATE FUNCTION tf2p(int[],anyelement) RETURNS int[] AS'select $1' LANGUAGE SQL;-- multi-arg polymorphicCREATE FUNCTION sum3(anyelement,anyelement,anyelement) returns anyelement AS'select $1+$2+$3' language sql strict;-- finalfn polymorphicCREATE FUNCTION ffp(anyarray) RETURNS anyarray AS'select $1' LANGUAGE SQL;-- finalfn non-polymorphicCREATE FUNCTION ffnp(int[]) returns int[] as'select $1' LANGUAGE SQL;-- Try to cover all the possible states:-- -- Note: in Cases 1 & 2, we are trying to return P. Therefore, if the transfn-- is stfnp, tfnp, or tf2p, we must use ffp as finalfn, because stfnp, tfnp,-- and tf2p do not return P. Conversely, in Cases 3 & 4, we are trying to-- return N. Therefore, if the transfn is stfp, tfp, or tf1p, we must use ffnp-- as finalfn, because stfp, tfp, and tf1p do not return N.---- Case1 (R = P) && (B = A)-- -------------------------- S tf1-- --------- N N-- should CREATECREATE AGGREGATE myaggp01a(*) (SFUNC = stfnp, STYPE = int4[], FINALFUNC = ffp, INITCOND = '{}');-- P N-- should ERROR: stfnp(anyarray) not matched by stfnp(int[])CREATE AGGREGATE myaggp02a(*) (SFUNC = stfnp, STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}');ERROR: cannot determine transition data typeDETAIL: An aggregate using a polymorphic transition type must have at least one polymorphic argument.-- N P-- should CREATECREATE AGGREGATE myaggp03a(*) (SFUNC = stfp, STYPE = int4[], FINALFUNC = ffp, INITCOND = '{}');CREATE AGGREGATE myaggp03b(*) (SFUNC = stfp, STYPE = int4[], INITCOND = '{}');-- P P-- should ERROR: we have no way to resolve SCREATE AGGREGATE myaggp04a(*) (SFUNC = stfp, STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}');ERROR: cannot determine transition data typeDETAIL: An aggregate using a polymorphic transition type must have at least one polymorphic argument.CREATE AGGREGATE myaggp04b(*) (SFUNC = stfp, STYPE = anyarray, INITCOND = '{}');ERROR: cannot determine transition data typeDETAIL: An aggregate using a polymorphic transition type must have at least one polymorphic argument.-- Case2 (R = P) && ((B = P) || (B = N))-- --------------------------------------- S tf1 B tf2-- ------------------------- N N N N-- should CREATECREATE AGGREGATE myaggp05a(BASETYPE = int, SFUNC = tfnp, STYPE = int[], FINALFUNC = ffp, INITCOND = '{}');-- N N N P-- should CREATECREATE AGGREGATE myaggp06a(BASETYPE = int, SFUNC = tf2p, STYPE = int[], FINALFUNC = ffp, INITCOND = '{}');-- N N P N-- should ERROR: tfnp(int[], anyelement) not matched by tfnp(int[], int)CREATE AGGREGATE myaggp07a(BASETYPE = anyelement, SFUNC = tfnp, STYPE = int[], FINALFUNC = ffp, INITCOND = '{}');ERROR: function tfnp(integer[], anyelement) does not exist-- N N P P-- should CREATECREATE AGGREGATE myaggp08a(BASETYPE = anyelement, SFUNC = tf2p, STYPE = int[], FINALFUNC = ffp, INITCOND = '{}');-- N P N N-- should CREATECREATE AGGREGATE myaggp09a(BASETYPE = int, SFUNC = tf1p, STYPE = int[], FINALFUNC = ffp, INITCOND = '{}');CREATE AGGREGATE myaggp09b(BASETYPE = int, SFUNC = tf1p, STYPE = int[], INITCOND = '{}');-- N P N P-- should CREATECREATE AGGREGATE myaggp10a(BASETYPE = int, SFUNC = tfp, STYPE = int[], FINALFUNC = ffp, INITCOND = '{}');CREATE AGGREGATE myaggp10b(BASETYPE = int, SFUNC = tfp, STYPE = int[], INITCOND = '{}');-- N P P N-- should ERROR: tf1p(int[],anyelement) not matched by tf1p(anyarray,int)CREATE AGGREGATE myaggp11a(BASETYPE = anyelement, SFUNC = tf1p, STYPE = int[], FINALFUNC = ffp, INITCOND = '{}');ERROR: function tf1p(integer[], anyelement) does not existCREATE AGGREGATE myaggp11b(BASETYPE = anyelement, SFUNC = tf1p, STYPE = int[], INITCOND = '{}');ERROR: function tf1p(integer[], anyelement) does not exist-- N P P P-- should ERROR: tfp(int[],anyelement) not matched by tfp(anyarray,anyelement)CREATE AGGREGATE myaggp12a(BASETYPE = anyelement, SFUNC = tfp, STYPE = int[], FINALFUNC = ffp, INITCOND = '{}');ERROR: function tfp(integer[], anyelement) does not existCREATE AGGREGATE myaggp12b(BASETYPE = anyelement, SFUNC = tfp, STYPE = int[], INITCOND = '{}');ERROR: function tfp(integer[], anyelement) does not exist-- P N N N-- should ERROR: tfnp(anyarray, int) not matched by tfnp(int[],int)CREATE AGGREGATE myaggp13a(BASETYPE = int, SFUNC = tfnp, STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}');ERROR: cannot determine transition data typeDETAIL: An aggregate using a polymorphic transition type must have at least one polymorphic argument.-- P N N P-- should ERROR: tf2p(anyarray, int) not matched by tf2p(int[],anyelement)CREATE AGGREGATE myaggp14a(BASETYPE = int, SFUNC = tf2p, STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}');ERROR: cannot determine transition data typeDETAIL: An aggregate using a polymorphic transition type must have at least one polymorphic argument.-- P N P N-- should ERROR: tfnp(anyarray, anyelement) not matched by tfnp(int[],int)CREATE AGGREGATE myaggp15a(BASETYPE = anyelement, SFUNC = tfnp, STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}');ERROR: function tfnp(anyarray, anyelement) does not exist-- P N P P-- should ERROR: tf2p(anyarray, anyelement) not matched by tf2p(int[],anyelement)CREATE AGGREGATE myaggp16a(BASETYPE = anyelement, SFUNC = tf2p, STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}');ERROR: function tf2p(anyarray, anyelement) does not exist-- P P N N-- should ERROR: we have no way to resolve SCREATE AGGREGATE myaggp17a(BASETYPE = int, SFUNC = tf1p, STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}');ERROR: cannot determine transition data typeDETAIL: An aggregate using a polymorphic transition type must have at least one polymorphic argument.CREATE AGGREGATE myaggp17b(BASETYPE = int, SFUNC = tf1p, STYPE = anyarray, INITCOND = '{}');ERROR: cannot determine transition data typeDETAIL: An aggregate using a polymorphic transition type must have at least one polymorphic argument.-- P P N P-- should ERROR: tfp(anyarray, int) not matched by tfp(anyarray, anyelement)CREATE AGGREGATE myaggp18a(BASETYPE = int, SFUNC = tfp, STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}');ERROR: cannot determine transition data typeDETAIL: An aggregate using a polymorphic transition type must have at least one polymorphic argument.CREATE AGGREGATE myaggp18b(BASETYPE = int, SFUNC = tfp, STYPE = anyarray, INITCOND = '{}');ERROR: cannot determine transition data typeDETAIL: An aggregate using a polymorphic transition type must have at least one polymorphic argument.-- P P P N-- should ERROR: tf1p(anyarray, anyelement) not matched by tf1p(anyarray, int)CREATE AGGREGATE myaggp19a(BASETYPE = anyelement, SFUNC = tf1p, STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}');ERROR: function tf1p(anyarray, anyelement) does not existCREATE AGGREGATE myaggp19b(BASETYPE = anyelement, SFUNC = tf1p, STYPE = anyarray, INITCOND = '{}');ERROR: function tf1p(anyarray, anyelement) does not exist-- P P P P-- should CREATECREATE AGGREGATE myaggp20a(BASETYPE = anyelement, SFUNC = tfp, STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}');CREATE AGGREGATE myaggp20b(BASETYPE = anyelement, SFUNC = tfp, STYPE = anyarray, INITCOND = '{}');-- Case3 (R = N) && (B = A)-- -------------------------- S tf1-- --------- N N-- should CREATECREATE AGGREGATE myaggn01a(*) (SFUNC = stfnp, STYPE = int4[], FINALFUNC = ffnp, INITCOND = '{}');CREATE AGGREGATE myaggn01b(*) (SFUNC = stfnp, STYPE = int4[], INITCOND = '{}');-- P N-- should ERROR: stfnp(anyarray) not matched by stfnp(int[])CREATE AGGREGATE myaggn02a(*) (SFUNC = stfnp, STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}');ERROR: cannot determine transition data typeDETAIL: An aggregate using a polymorphic transition type must have at least one polymorphic argument.CREATE AGGREGATE myaggn02b(*) (SFUNC = stfnp, STYPE = anyarray, INITCOND = '{}');ERROR: cannot determine transition data typeDETAIL: An aggregate using a polymorphic transition type must have at least one polymorphic argument.-- N P-- should CREATECREATE AGGREGATE myaggn03a(*) (SFUNC = stfp, STYPE = int4[], FINALFUNC = ffnp, INITCOND = '{}');-- P P-- should ERROR: ffnp(anyarray) not matched by ffnp(int[])CREATE AGGREGATE myaggn04a(*) (SFUNC = stfp, STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}');ERROR: cannot determine transition data typeDETAIL: An aggregate using a polymorphic transition type must have at least one polymorphic argument.-- Case4 (R = N) && ((B = P) || (B = N))-- --------------------------------------- S tf1 B tf2-- ------------------------- N N N N-- should CREATECREATE AGGREGATE myaggn05a(BASETYPE = int, SFUNC = tfnp, STYPE = int[], FINALFUNC = ffnp, INITCOND = '{}');CREATE AGGREGATE myaggn05b(BASETYPE = int, SFUNC = tfnp, STYPE = int[], INITCOND = '{}');-- N N N P-- should CREATECREATE AGGREGATE myaggn06a(BASETYPE = int, SFUNC = tf2p, STYPE = int[], FINALFUNC = ffnp, INITCOND = '{}');CREATE AGGREGATE myaggn06b(BASETYPE = int, SFUNC = tf2p, STYPE = int[], INITCOND = '{}');-- N N P N-- should ERROR: tfnp(int[], anyelement) not matched by tfnp(int[], int)CREATE AGGREGATE myaggn07a(BASETYPE = anyelement, SFUNC = tfnp, STYPE = int[], FINALFUNC = ffnp, INITCOND = '{}');ERROR: function tfnp(integer[], anyelement) does not existCREATE AGGREGATE myaggn07b(BASETYPE = anyelement, SFUNC = tfnp, STYPE = int[], INITCOND = '{}');ERROR: function tfnp(integer[], anyelement) does not exist-- N N P P-- should CREATECREATE AGGREGATE myaggn08a(BASETYPE = anyelement, SFUNC = tf2p, STYPE = int[], FINALFUNC = ffnp, INITCOND = '{}');CREATE AGGREGATE myaggn08b(BASETYPE = anyelement, SFUNC = tf2p, STYPE = int[], INITCOND = '{}');-- N P N N-- should CREATECREATE AGGREGATE myaggn09a(BASETYPE = int, SFUNC = tf1p, STYPE = int[], FINALFUNC = ffnp, INITCOND = '{}');-- N P N P-- should CREATECREATE AGGREGATE myaggn10a(BASETYPE = int, SFUNC = tfp, STYPE = int[], FINALFUNC = ffnp, INITCOND = '{}');-- N P P N-- should ERROR: tf1p(int[],anyelement) not matched by tf1p(anyarray,int)CREATE AGGREGATE myaggn11a(BASETYPE = anyelement, SFUNC = tf1p, STYPE = int[], FINALFUNC = ffnp, INITCOND = '{}');ERROR: function tf1p(integer[], anyelement) does not exist-- N P P P-- should ERROR: tfp(int[],anyelement) not matched by tfp(anyarray,anyelement)CREATE AGGREGATE myaggn12a(BASETYPE = anyelement, SFUNC = tfp, STYPE = int[], FINALFUNC = ffnp, INITCOND = '{}');ERROR: function tfp(integer[], anyelement) does not exist-- P N N N-- should ERROR: tfnp(anyarray, int) not matched by tfnp(int[],int)CREATE AGGREGATE myaggn13a(BASETYPE = int, SFUNC = tfnp, STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}');ERROR: cannot determine transition data typeDETAIL: An aggregate using a polymorphic transition type must have at least one polymorphic argument.CREATE AGGREGATE myaggn13b(BASETYPE = int, SFUNC = tfnp, STYPE = anyarray, INITCOND = '{}');ERROR: cannot determine transition data typeDETAIL: An aggregate using a polymorphic transition type must have at least one polymorphic argument.-- P N N P-- should ERROR: tf2p(anyarray, int) not matched by tf2p(int[],anyelement)CREATE AGGREGATE myaggn14a(BASETYPE = int, SFUNC = tf2p, STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}');ERROR: cannot determine transition data typeDETAIL: An aggregate using a polymorphic transition type must have at least one polymorphic argument.CREATE AGGREGATE myaggn14b(BASETYPE = int, SFUNC = tf2p, STYPE = anyarray, INITCOND = '{}');ERROR: cannot determine transition data typeDETAIL: An aggregate using a polymorphic transition type must have at least one polymorphic argument.-- P N P N-- should ERROR: tfnp(anyarray, anyelement) not matched by tfnp(int[],int)CREATE AGGREGATE myaggn15a(BASETYPE = anyelement, SFUNC = tfnp, STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}');ERROR: function tfnp(anyarray, anyelement) does not existCREATE AGGREGATE myaggn15b(BASETYPE = anyelement, SFUNC = tfnp,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?