{"id":712,"date":"2012-07-30T09:19:17","date_gmt":"2012-03-01T17:02:46","guid":{"rendered":"http:\/\/blog.light42.com\/wordpress\/?p=712"},"modified":"2013-09-07T17:33:47","modified_gmt":"2013-09-08T00:33:47","slug":"plr-median","status":"publish","type":"post","link":"http:\/\/blog.light42.com\/wordpress\/?p=712","title":{"rendered":"plr median"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/blog.light42.com\/wordpress\/wp-content\/uploads\/2012\/06\/PostgreSQL_logo.3colors.120x120.png\" alt=\"pg_logo\" align=\"right\" height=108px width=108px \/><\/p>\n<p><code><br \/>\n----------------------------------------- install ------------<br \/>\ncreate or replace function r_median(_float8) returns float as '<br \/>\n  median(arg1)<br \/>\n' language 'plr';<\/p>\n<p>CREATE AGGREGATE median (<br \/>\n  sfunc = plr_array_accum,<br \/>\n  basetype = float8,<br \/>\n  stype = _float8,<br \/>\n  finalfunc = r_median<br \/>\n);<br \/>\n<\/code><\/p>\n<p><code><br \/>\n----------------------------------------- test ---------------<br \/>\nselect max(a.res),avg(a.res),median(a.res),min(a.res)<br \/>\nfrom<br \/>\n  ( select (st_area(wkb_geometry) - shape_area) as res<br \/>\n     from landtypes_090911_marin_parcel_adjusted) a;<\/p>\n<p>thuban1 Time: 21255 ms<br \/>\nr900    Time: 13880 ms<br \/>\nps      Time:  9337 ms<br \/>\nmacpro  Time:  8856 ms<br \/>\ni7-960+ Time:  6980 ms<br \/>\n<\/code><\/p>\n<p>\n<em>ps-<\/em> add standard deviation <strong>sd<\/strong> too<br \/>\n<em>pps-<\/em> just noticed <a href=\"http:\/\/www.fuzzy.cz\/en\/articles\/calculating-quantiles-and-trimmed-aggregates\/\" title=\"r_quantile\" target=\"_blank\">this post<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; install &#8212;&#8212;&#8212;&#8212; create or replace function r_median(_float8) returns float as &#8216; median(arg1) &#8216; language &#8216;plr&#8217;; CREATE AGGREGATE median ( sfunc = plr_array_accum, basetype = float8, stype = _float8, finalfunc = r_median ); &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; test &#8212;&#8212;&#8212;&#8212;&#8212; select max(a.res),avg(a.res),median(a.res),min(a.res) from ( select (st_area(wkb_geometry) &#8211; shape_area) as res from landtypes_090911_marin_parcel_adjusted) a; thuban1 Time: 21255 ms r900 Time: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"_links":{"self":[{"href":"http:\/\/blog.light42.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/712"}],"collection":[{"href":"http:\/\/blog.light42.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.light42.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.light42.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.light42.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=712"}],"version-history":[{"count":12,"href":"http:\/\/blog.light42.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/712\/revisions"}],"predecessor-version":[{"id":1305,"href":"http:\/\/blog.light42.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/712\/revisions\/1305"}],"wp:attachment":[{"href":"http:\/\/blog.light42.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=712"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.light42.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=712"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.light42.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}