Hi tom.

In postgresql you cannot have functions with
a variable number of parameters.
(pgsql supports some kind of method overloading
based on the type and number of parameters,
thats the reason why).

But if you run Unix (with freebsd and linux it is trivial
as you will see, with solaris you have to be more formal)
there is a hack.

I had the same problem as yours, but in my case
i wanted the minimum, maximum of double numbers (maximum 14 of them).

In BSD,linux you can navigate the process' stack with no problems.
The idea is to write a variable parameter number function,
with the first parameter denoting the number of the rest
parameters, (just like printf)
and then define a pgsql function with the maximum number
of parameters that you will ever have.

I attach the code (tested under RedHat 7.1, kernel 2.4.7,
glibc-2.2.2-10,gcc-2.96-81 and FreeBSD 4.6.1-RC2, both with
postgresql 7.2.1),



==================================================================
Achilleus Mantzios
S/W Engineer
IT dept
Dynacom Tankers Mngmt
Nikis 4, Glyfada
Athens 16610
Greece
tel:    +30-10-8981112
fax:    +30-10-8981877
email:  [EMAIL PROTECTED]
        [EMAIL PROTECTED]
#include <pgsql/include/server/postgres.h>
#include <stdio.h>
int minihack(argc)
int argc;
{
        int i;
        int temp = *(&argc + 1);
        int tval;
        for (i=1;i<argc;i++) {
                tval = *(&argc+1+i);
                if (tval < temp && tval !=0)
                        temp = tval;
        }
        return temp;
}
int4 mini(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14) 
int4 t1;
int4 t2;
int4 t3;
int4 t4;
int4 t5;
int4 t6;
int4 t7;
int4 t8;
int4 t9;
int4 t10;
int4 t11;
int4 t12;
int4 t13;
int4 t14;
{
        return minihack(14,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14);
}
int maxihack(argc)
int argc;
{
        int i;
        int temp = *(&argc + 1);
        int tval;
        for (i=1;i<argc;i++) {
                tval = *(&argc+1+i);
                if (tval > temp)
                        temp = tval;
        }
        return temp;
}
int4 maxi(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14) 
int4 t1;
int4 t2;
int4 t3;
int4 t4;
int4 t5;
int4 t6;
int4 t7;
int4 t8;
int4 t9;
int4 t10;
int4 t11;
int4 t12;
int4 t13;
int4 t14;
{
        return maxihack(14,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14);
}
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Reply via email to