http://www.postgresonline.com/journal/archives/239-The-wonders-of-Any-Element.html
定义函数
pgsql=# CREATE OR REPLACE FUNCTION diff_inc(IN anyelement, IN anyelement pgsql(# , OUT diff integer, OUT f_val anyelement, OUT l_val anyelement) pgsql-# RETURNS record pgsql-# AS pgsql-# $$ pgsql$# BEGIN pgsql$# diff = ($1 - $2)::integer; pgsql$# f_val = $1 +1; pgsql$# l_val = $2 +1; pgsql$# END; pgsql$# $$ pgsql-# language plpgsql; CREATE FUNCTION pgsql=#
带入不同的数据类型进行运算:
pgsql=# select (diff_inc(12,14)).*; diff | f_val | l_val ------+-------+------- -2 | 13 | 15 (1 row) pgsql=# SELECT (diff_inc('2011-12-31'::date, '2012-01-05'::date)).*; diff | f_val | l_val ------+------------+------------ -5 | 2012-01-01 | 2012-01-06 (1 row) pgsql=#
但是,它有一个限制:一旦第一个参数确定,后面的参数必须和它的类型一致。
本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/p/3190622.html,如需转载请自行联系原作者