From: | Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com> |
---|---|
To: | Pg Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Function accepting array of complex type |
Date: | 2015-08-25 22:21:21 |
Message-ID: | 55DCEA61.8090805@BlueTreble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
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 $$
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)] );
ERROR: function magsum(record[]) does not exist at character 8
Presumably we're playing some games with resolving (...) into a complex
type instead of a raw record; what would be involved with making that
work for an array of a complex type? I don't see anything array-specific
in parse_func.c, so I'm not sure what the path for this is...
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com
From | Date | Subject | |
---|---|---|---|
Next Message | Vignesh Raghunathan | 2015-08-25 22:23:21 | Re: Using HeapTuple.t_len to verify size of tuple |
Previous Message | Tom Lane | 2015-08-25 22:09:17 | Re: 9.4 broken on alpha |