SQL, get median of all columns in each row

In PostgreSQL database, table T has multiple numeric columns:


X Y Z
1 6 3 3
2 5 6 NULL
3 4 5 6
4 11 7 8

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


MEDIAN
1 3
2 5
3 5
4 8

Write the following SPL code:


A
1 =pg1.query("select * from T")
2 =A1.new(~.array().median())

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

Source:https://stackoverflow.com/questions/78449368/how-to-get-the-row-wise-median-over-several-columns-of-a-postgresql-table