shlogg · Early preview
Judy @esproc_spl

Calculating Median Values For Multiple Columns In PostgreSQL

In PostgreSQL, use SPL code: new() function & array() to find median of all column values in each row.

In PostgreSQL database, table T has multiple numeric columns:

We want to find the median of all column values in each row. Below is the expected result:

Write the following SPL code:

new()function creates a new two-dimensional table; ~ represents the current record; array() function converts field values of a record to a sequence.