pgsql: Support "variadic" functions, which can accept a variable number

Started by Tom Lanealmost 18 years ago3 messagescomitters
Jump to latest
#1Tom Lane
tgl@sss.pgh.pa.us

Log Message:
-----------
Support "variadic" functions, which can accept a variable number of arguments
so long as all the trailing arguments are of the same (non-array) type.
The function receives them as a single array argument (which is why they
have to all be the same type).

It might be useful to extend this facility to aggregates, but this patch
doesn't do that.

This patch imposes a noticeable slowdown on function lookup --- a follow-on
patch will fix that by adding a redundant column to pg_proc.

Pavel Stehule

Modified Files:
--------------
pgsql/doc/src/sgml:
catalogs.sgml (r2.168 -> r2.169)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/doc/src/sgml/catalogs.sgml?r1=2.168&r2=2.169)
extend.sgml (r1.36 -> r1.37)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/doc/src/sgml/extend.sgml?r1=1.36&r2=1.37)
plpgsql.sgml (r1.131 -> r1.132)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/doc/src/sgml/plpgsql.sgml?r1=1.131&r2=1.132)
typeconv.sgml (r1.54 -> r1.55)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/doc/src/sgml/typeconv.sgml?r1=1.54&r2=1.55)
xfunc.sgml (r1.130 -> r1.131)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/doc/src/sgml/xfunc.sgml?r1=1.130&r2=1.131)
pgsql/doc/src/sgml/ref:
alter_function.sgml (r1.15 -> r1.16)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/doc/src/sgml/ref/alter_function.sgml?r1=1.15&r2=1.16)
comment.sgml (r1.36 -> r1.37)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/doc/src/sgml/ref/comment.sgml?r1=1.36&r2=1.37)
create_function.sgml (r1.78 -> r1.79)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/doc/src/sgml/ref/create_function.sgml?r1=1.78&r2=1.79)
drop_function.sgml (r1.33 -> r1.34)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/doc/src/sgml/ref/drop_function.sgml?r1=1.33&r2=1.34)
pgsql/src/backend/catalog:
information_schema.sql (r1.43 -> r1.44)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/catalog/information_schema.sql?r1=1.43&r2=1.44)
namespace.c (r1.107 -> r1.108)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/catalog/namespace.c?r1=1.107&r2=1.108)
pg_aggregate.c (r1.93 -> r1.94)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/catalog/pg_aggregate.c?r1=1.93&r2=1.94)
pgsql/src/backend/commands:
functioncmds.c (r1.95 -> r1.96)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/commands/functioncmds.c?r1=1.95&r2=1.96)
pgsql/src/backend/nodes:
copyfuncs.c (r1.394 -> r1.395)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/nodes/copyfuncs.c?r1=1.394&r2=1.395)
equalfuncs.c (r1.323 -> r1.324)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/nodes/equalfuncs.c?r1=1.323&r2=1.324)
outfuncs.c (r1.326 -> r1.327)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/nodes/outfuncs.c?r1=1.326&r2=1.327)
pgsql/src/backend/parser:
gram.y (r2.616 -> r2.617)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/parser/gram.y?r1=2.616&r2=2.617)
keywords.c (r1.198 -> r1.199)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/parser/keywords.c?r1=1.198&r2=1.199)
parse_expr.c (r1.228 -> r1.229)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/parser/parse_expr.c?r1=1.228&r2=1.229)
parse_func.c (r1.202 -> r1.203)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/parser/parse_func.c?r1=1.202&r2=1.203)
parse_utilcmd.c (r2.13 -> r2.14)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/parser/parse_utilcmd.c?r1=2.13&r2=2.14)
pgsql/src/backend/utils/adt:
regproc.c (r1.107 -> r1.108)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/utils/adt/regproc.c?r1=1.107&r2=1.108)
ruleutils.c (r1.275 -> r1.276)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/utils/adt/ruleutils.c?r1=1.275&r2=1.276)
pgsql/src/backend/utils/fmgr:
funcapi.c (r1.39 -> r1.40)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/utils/fmgr/funcapi.c?r1=1.39&r2=1.40)
pgsql/src/bin/pg_dump:
pg_dump.c (r1.493 -> r1.494)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/bin/pg_dump/pg_dump.c?r1=1.493&r2=1.494)
pgsql/src/bin/psql:
describe.c (r1.181 -> r1.182)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/bin/psql/describe.c?r1=1.181&r2=1.182)
pgsql/src/include/catalog:
catversion.h (r1.468 -> r1.469)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/include/catalog/catversion.h?r1=1.468&r2=1.469)
namespace.h (r1.54 -> r1.55)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/include/catalog/namespace.h?r1=1.54&r2=1.55)
pg_proc.h (r1.506 -> r1.507)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/include/catalog/pg_proc.h?r1=1.506&r2=1.507)
pgsql/src/include/nodes:
parsenodes.h (r1.366 -> r1.367)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/include/nodes/parsenodes.h?r1=1.366&r2=1.367)
pgsql/src/include/parser:
parse_func.h (r1.59 -> r1.60)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/include/parser/parse_func.h?r1=1.59&r2=1.60)
pgsql/src/interfaces/ecpg/preproc:
preproc.y (r1.368 -> r1.369)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/interfaces/ecpg/preproc/preproc.y?r1=1.368&r2=1.369)
pgsql/src/pl/plpgsql/src:
pl_comp.c (r1.126 -> r1.127)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/pl/plpgsql/src/pl_comp.c?r1=1.126&r2=1.127)
pgsql/src/pl/plpython:
plpython.c (r1.110 -> r1.111)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/pl/plpython/plpython.c?r1=1.110&r2=1.111)
pgsql/src/test/regress/expected:
plpgsql.out (r1.64 -> r1.65)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/expected/plpgsql.out?r1=1.64&r2=1.65)
polymorphism.out (r1.12 -> r1.13)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/expected/polymorphism.out?r1=1.12&r2=1.13)
pgsql/src/test/regress/sql:
plpgsql.sql (r1.54 -> r1.55)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/sql/plpgsql.sql?r1=1.54&r2=1.55)
polymorphism.sql (r1.5 -> r1.6)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/test/regress/sql/polymorphism.sql?r1=1.5&r2=1.6)

#2Simon Riggs
simon@2ndQuadrant.com
In reply to: Tom Lane (#1)
Re: pgsql: Support "variadic" functions, which can accept a variable number

On Wed, 2008-07-16 at 01:30 +0000, Tom Lane wrote:

create_function.sgml (r1.78 -> r1.79)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/doc/src/sgml/ref/create_function.sgml?r1=1.78&r2=1.79)

I think CREATE FUNCTION should specifically mention that VARIADIC can
only be used as the arg mode of the last parameter. Other pages mention
this, but the syntax doesn't, which could confuse people. Like me, who
started with the CREATE FUNCTION page, rather than other parts of the
docs.

--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Training, Services and Support

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Simon Riggs (#2)
Re: pgsql: Support "variadic" functions, which can accept a variable number

Simon Riggs <simon@2ndquadrant.com> writes:

I think CREATE FUNCTION should specifically mention that VARIADIC can
only be used as the arg mode of the last parameter. Other pages mention
this, but the syntax doesn't, which could confuse people. Like me, who
started with the CREATE FUNCTION page, rather than other parts of the
docs.

Done in connection with the TABLE-function docs update.

regards, tom lane