| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com> |
| Cc: | Pg Hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: Function accepting array of complex type |
| Date: | 2015-08-25 23:28:19 |
| Message-ID: | 24251.1440545299@sss.pgh.pa.us |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)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 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
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[] );
magsum
------------------
6.08111831820431
(1 row)
regards, tom lane
| From | Date | Subject | |
|---|---|---|---|
| Next Message | David G. Johnston | 2015-08-25 23:29:31 | Re: Function accepting array of complex type |
| Previous Message | Tom Lane | 2015-08-25 23:22:04 | Re: Custom Scans and private data |