To get the median in postgreSQL, use a percentile function.
It's called ordered set aggregate syntax. The only argument to the function is a number between 0 and 1 corresponding to the percentile you want. You then type "within group", and then, inside parentheses, order by and the name of the column you want to compute the percentile for.