multiple paramters in aggregate function - Mailing list pgsql-general

From Sim Zacks
Subject multiple paramters in aggregate function
Date
Msg-id 4A83F045.4020007@compulab.co.il
Whole thread Raw
Responses R: multiple paramters in aggregate function  (Scara Maccai <m_lists@yahoo.it>)
Re: multiple paramters in aggregate function  (Alban Hertroys <dalroi@solfertje.student.utwente.nl>)
Re: multiple paramters in aggregate function  (Alvaro Herrera <alvherre@commandprompt.com>)
List pgsql-general
According to the documentation, you can pass multiple parameters into an
aggregate function, but it only stores one value.


What I am trying to do is sum a quantity field, but it also has units
that need to be converted.

My function should take 2 values, the quantity and the unit, determine
which unit to use, the one in state or the passed in one and to convert
either the quantity in state or the quantity passed in and add it to the
other quantity.

In other words:

4 meter

400 mm

100 cm


I want to sum it all, my function decides to use meter (based on the
requirements) and should return 4.00104 (or something like that) and
then I have a second aggregate function which just chooses which unit to
use, so in my query I use 2 aggregate functions, one gives me the sum of
converted quantity and the other gives me which unit it is in.


Currently, the only way I can think of doing this is by keeping an array
in state.

Is there a better way?


Thank you

Sim


pgsql-general by date:

Previous
From: Sam Mason
Date:
Subject: Re: Looping through string constants
Next
From: Scara Maccai
Date:
Subject: Re: totally different plan when using partitions + request