Re: [HACKERS] Function accepting array of complex type

2015-08-28 Thread Tom Lane
Jim Nasby jim.na...@bluetreble.com 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

Re: [HACKERS] Function accepting array of complex type

2015-08-28 Thread Jim Nasby
On 8/25/15 6:28 PM, Tom Lane wrote: Jim Nasby jim.na...@bluetreble.com 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

Re: [HACKERS] Function accepting array of complex type

2015-08-26 Thread Andrew Dunstan
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 --

[HACKERS] Function accepting array of complex type

2015-08-25 Thread Jim Nasby
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 $$

Re: [HACKERS] Function accepting array of complex type

2015-08-25 Thread David G. Johnston
On Tue, Aug 25, 2015 at 6:21 PM, Jim Nasby jim.na...@bluetreble.com 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

Re: [HACKERS] Function accepting array of complex type

2015-08-25 Thread Tom Lane
Jim Nasby jim.na...@bluetreble.com 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