On Mon, Jul 20, 2015 at 10:06 AM, Paul A Jungwirth <p...@illuminatedcomputing.com> wrote: >> The above implementation of "first" aggregate returns the first non-NULL item >> value. > > I'm curious what advantages this approach has over these FIRST/LAST > functions from the Wiki?: > > https://wiki.postgresql.org/wiki/First/last_%28aggregate%29 > > Also to get the "first non-null value" you can apply an ordering to > just the aggregate function, e.g.: > > select first(id order by start_time nulls last) from events; > > If you want speed you should probably write a C version.
C functions come with a lot of administration headaches, and the performance gain will probably not be significant unless you totally bypass the SPI interface. Even then, I suspect (vs the pl/pgsql variant which caches plan) the majority of overhead is is in calling the function, not the actual implementation. It's be interesting to see the results though. merlin -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers