idea: simple variadic functions in SQL and PL/pgSQL
От | Pavel Stehule |
---|---|
Тема | idea: simple variadic functions in SQL and PL/pgSQL |
Дата | |
Msg-id | 162867790802240854t5e9d43end50bd72ee00f4c9a@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: idea: simple variadic functions in SQL and PL/pgSQL
|
Список | pgsql-hackers |
Hello, I found easy implementation of variadic functions. It's based on adapation FuncnameGetCandidates. When I found variadic function, then I should create accurate number of last arguments (diff between pronargs and nargs). Variadic function can be signed via flag or via some pseudotype. Flag is better - allows variadic arguments of any type. In static languages (like SQL or PL/pgSQL) variadic variables can ba accessed via array (variadic arguments can be only nonarray). This isn't problem in C language, there are arguments available directly. Sample: CREATE OR REPLACE FUNCTION Least(anyelement) RETURNS anyelement AS $$ SELECT MIN($1[i]) FROM generate_series(1, array_upper($1,1)) g(i); $$ LANGUAGE SQL IMMUTABLE VARIADIC. This sample is really simple. The goal is support sophistic libraries like JSON support: http://www.mysqludf.org/lib_mysqludf_json/index.php Main change in FuncnameGetCandidates. if (!OidIsValid(variadic_oid)) { memcpy(newResult->args, procform->proargtypes.values, pronargs * sizeof(Oid)); } else { int j; /* copy nonvariadic parameters */ memcpy(newResult->args, procform->proargtypes.values, pronargs * sizeof(Oid)); /* set variadic parameters,!!!!!!!!!!! */ for (j = pronargs - 1; j < nargs; j++) newResult->args[j]= variadic_oid; } I invite any ideas, notes Regards Pavel Stehule
В списке pgsql-hackers по дате отправления: