Jim Nasby writes:
> On 8/25/15 6:28 PM, Tom Lane wrote:
>> You need to cast it to some specific record type:
>> regression=# SELECT magsum( array[row(2.1, 2.1), row(2.2,2.2)]::c[] );
> Right, I was wondering how hard it would be to improve that, but it's
> not clear to me where to look at in the
On 8/25/15 6:28 PM, Tom Lane wrote:
Jim Nasby writes:
This works:
CREATE TYPE c AS (r float, i float);
CREATE FUNCTION mag(c c) RETURNS float LANGUAGE sql AS $$
SELECT sqrt(c.r^2 + c.i^2)
$$;
SELECT mag( (2.2, 2.2) );
mag
--
3.11126983722081
But this doesn't:
CREA
On 08/25/2015 06:21 PM, Jim Nasby wrote:
CREATE FUNCTION magsum( c c[] ) RETURNS float LANGUAGE sql AS $$
SELECT sum(sqrt(c.r^2 + c.i^2)) FROM unnest(c) c
$$;
SELECT magsum( array[row(2.1, 2.1), row(2.2,2.2)] );
SELECT magsum( array[row(2.1, 2.1), row(2.2,2.2)]::c[] );
cheers
andrew
--
On Tue, Aug 25, 2015 at 6:21 PM, Jim Nasby wrote:
> This works:
>
> CREATE TYPE c AS (r float, i float);
> CREATE FUNCTION mag(c c) RETURNS float LANGUAGE sql AS $$
> SELECT sqrt(c.r^2 + c.i^2)
> $$;
> SELECT mag( (2.2, 2.2) );
>mag
> --
> 3.11126983722081
>
> But this do
Jim Nasby writes:
> This works:
> CREATE TYPE c AS (r float, i float);
> CREATE FUNCTION mag(c c) RETURNS float LANGUAGE sql AS $$
> SELECT sqrt(c.r^2 + c.i^2)
> $$;
> SELECT mag( (2.2, 2.2) );
> mag
> --
> 3.11126983722081
> But this doesn't:
> CREATE FUNCTION magsum( c
This works:
CREATE TYPE c AS (r float, i float);
CREATE FUNCTION mag(c c) RETURNS float LANGUAGE sql AS $$
SELECT sqrt(c.r^2 + c.i^2)
$$;
SELECT mag( (2.2, 2.2) );
mag
--
3.11126983722081
But this doesn't:
CREATE FUNCTION magsum( c c[] ) RETURNS float LANGUAGE sql AS $$
S