This repository has been archived by the owner. It is now read-only.
Median function for PostgreSQL
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.gitignore
Gemfile
README.md
Rakefile
postgresql.sql

README.md

Median.sql

Starting with Postgres 9.4, use PERCENTILE_CONT instead


Adds a median function to Postgres

Found on postgresonline.com in a comment by Mike.

SELECT median(n) FROM generate_series(1, 5, 1) n;
-- 3

SELECT median(n) FROM generate_series(1, 6, 1) n;
-- 3.5

SELECT median(n) FROM generate_series(1, 0) n;
-- NULL

Installation

Run this SQL