PostgreSQL中 AnyElement AnyArray AnynonArray的区别与联系

http://www.postgresql.org/docs/current/static/extend-type-system.html#EXTEND-TYPES-POLYMORPHIC

先看一个例子:

CREATE OR REPLACE FUNCTION myappend01(anyelement, anyelement) RETURNS anyelement AS
$$
SELECT $1 || $2;
$$ LANGUAGE SQL;

执行(按 AnynonArray来传递输入参数):

pgsql=# select myappend01('abc', 'def');
ERROR:  could not determine polymorphic type because input has type "unknown"
pgsql=# 
pgsql=# select myappend01('abc'::text, 'def'::text);
 myappend01 
------------
 abcdef
(1 row)

pgsql=# 

执行(按 AnyArray来传递输入参数):

pgsql=# select myappend01(ARRAY['mm','nn'], ARRAY['xx','yy']);
  myappend01   
---------------
 {mm,nn,xx,yy}
(1 row)

可以认为 AnyElement = AnyArray || AnynonArray

再看一个例子:

pgsql=# select myappend02('abc', 'def');
ERROR:  could not determine polymorphic type because input has type "unknown"
pgsql=# 
pgsql=# 
pgsql=# select myappend02('abc'::text, 'def'::text);
 myappend02 
------------
 abcdef
(1 row)

pgsql=#
pgsql=# select myappend02(ARRAY['aa','bb'], ARRAY['cc','dd']);
ERROR:  function myappend02(text[], text[]) does not exist
LINE 1: select myappend02(ARRAY['aa','bb'], ARRAY['cc','dd']);
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
pgsql=# 

 

posted @ 2013-07-15 14:18  健哥的数据花园  阅读(1852)  评论(0编辑  收藏  举报