Re: Function accepting array of complex type
От | Jim Nasby |
---|---|
Тема | Re: Function accepting array of complex type |
Дата | |
Msg-id | 55E0BD22.1060409@BlueTreble.com обсуждение исходный текст |
Ответ на | Re: Function accepting array of complex type (Tom Lane <tgl@sss.pgh.pa.us>) |
Ответы |
Re: Function accepting array of complex type
|
Список | pgsql-hackers |
On 8/25/15 6:28 PM, Tom Lane wrote: > Jim Nasby <Jim.Nasby@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 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[] ); 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 code. Does the resolution happen as part of parsing, or is it further down the road? -- 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
В списке pgsql-hackers по дате отправления: