Re: [GENERAL] multiple paramters in aggregate function

2009-08-20 Thread Karsten Hilbert
On Thu, Aug 20, 2009 at 03:30:00PM +0300, Sim Zacks wrote: > In other words, I have a conversion table of all different units. If > there is no conversion between 2 units (such as volume and area) then > the sum returns null. > > > Shouldn't that return NULL IOW unkno

Re: [GENERAL] multiple paramters in aggregate function

2009-08-20 Thread Sim Zacks
In other words, I have a conversion table of all different units. If there is no conversion between 2 units (such as volume and area) then the sum returns null. Shouldn't that return NULL IOW unknown ? Karsten I am not familiar with returning unknown. I know that accord

Re: [GENERAL] multiple paramters in aggregate function

2009-08-20 Thread Karsten Hilbert
On Thu, Aug 20, 2009 at 10:36:37AM +0300, Sim Zacks wrote: > In other words, I have a conversion table of all different units. If > there is no conversion between 2 units (such as volume and area) then > the sum returns null. Shouldn't that return NULL IOW unknown ? Karsten -- GPG key ID E40713

Re: [GENERAL] multiple paramters in aggregate function

2009-08-20 Thread Sim Zacks
> My query contains select .., > sum_unitvalues(qty,unitid),sum_units(unitid),... > then the units returned do not have to be known in advance, which is > important in this specific project. > To give an example of my required result set: unitid 1 = mm 2 = inch 3 = ft 4 = gram create table te

Re: [GENERAL] multiple paramters in aggregate function

2009-08-20 Thread Sim Zacks
>> That would be true if all units were always convertible to mm, but we >> have volume also, we also have feet etc.. So that the easiest and > > How did you plan on solving that in your multiple-argument aggregate? > Fake their value by adding 0? That's no different for my suggested > solution. W

Re: [GENERAL] multiple paramters in aggregate function

2009-08-18 Thread Alban Hertroys
On 18 Aug 2009, at 6:51, Sim Zacks wrote: That would be true if all units were always convertible to mm, but we have volume also, we also have feet etc.. So that the easiest and How did you plan on solving that in your multiple-argument aggregate? Fake their value by adding 0? That's no diff

Re: [GENERAL] multiple paramters in aggregate function

2009-08-17 Thread Sim Zacks
That would be true if all units were always convertible to mm, but we have volume also, we also have feet etc.. So that the easiest and cleanest thing to do, with out having to throw the all the functions into a case statement is an aggregate function that takes the 2 unit types and then gives back

Re: [GENERAL] multiple paramters in aggregate function

2009-08-13 Thread Alvaro Herrera
Sim Zacks wrote: > 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. Have you seen Martijn van Oosterhout's tagged t

Re: [GENERAL] multiple paramters in aggregate function

2009-08-13 Thread Scara Maccai
> That could work in some cases, however in our case it would > not produce > desirable results. Well I don't think you got Alban's suggestion right... What he was trying to say was: - use a regular (not aggregated) function to convert all measures to mm - use the normal SUM() to sum those value

Re: [GENERAL] multiple paramters in aggregate function

2009-08-13 Thread Sim Zacks
> It's probably easiest to decide on an internal unit to use in your > aggregate and only convert it to the desired unit once you're done > summing them. I'd probably convert all measurements to mm in the > function and summarise those. That could work in some cases, however in our case it would no

Re: [GENERAL] multiple paramters in aggregate function

2009-08-13 Thread Alban Hertroys
On 13 Aug 2009, at 12:51, Sim Zacks wrote: What I am trying to do is sum a quantity field, but it also has units that need to be converted. 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

R: [GENERAL] multiple paramters in aggregate function

2009-08-13 Thread Scara Maccai
> Is there a better way? I think you could use a User Data Type. Then pass that as parameter to your aggregate function. That is: you would pass (4, 'meter') (400, 'mm') (100, 'cm') to your aggregate function. Each one is a user datatype: CREATE TYPE mytype AS ( v double precisio

[GENERAL] multiple paramters in aggregate function

2009-08-13 Thread Sim Zacks
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