Re: Sum of Every Column

From: Achilleus Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
To: Tom Haddon <tom(at)haddons(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Sum of Every Column
Date: 2002-10-24 07:36:54
Message-ID: Pine.LNX.4.44.0210240954280.26588-200000@matrix.gatewaynet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


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: achill(at)matrix(dot)gatewaynet(dot)com
mantzios(at)softlab(dot)ece(dot)ntua(dot)gr

Attachment Content-Type Size
mini_maxi.c text/plain 1018 bytes

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Christoph Haller 2002-10-24 07:56:46 Re: 'next' or similar in plpgsql
Previous Message peter 2002-10-24 06:42:52 Re: Multiple Databases