Language
PostgreSQL
- First appeared
- 1996
- Paradigm
- Declarative (SQL)
- Toolchain
- PostgreSQL 18.6
- Container image
postgres:18.6-trixie
SQL is where most data already lives, and PostgreSQL brings a lot of
statistics with it: avg, stddev_samp, var_samp, percentile_cont,
corr, and regr_slope are all built-in aggregates. The from-scratch
versions avoid them and use only basic aggregates such as sum, count,
min, and max, plus ordinary arithmetic and window functions. SQL describes results rather than steps, so iterative
methods take some ingenuity: k-means repeats its two steps with a recursive
query, WITH RECURSIVE.
Quirks
- The runner loads
data.csvinto a table nameddata, with numeric columns asdouble precisionand arow_idcolumn numbering rows in file order, from 1. Tables otherwise have no order. - The final query returns two columns,
nameandvalue, one row per result. - Integer division truncates:
7 / 2is3, and7 / 2.0is3.5.
Concepts in PostgreSQL
- Cross-validation
- Decision tree
- Descriptive statistics
- k-means clustering
- k-nearest neighbors
- Linear regression
- Logistic regression
- Naive Bayes
- Principal component analysis
- Descriptive statistics (built-in)
- Linear regression (built-in)
Run the examples locally
You need Docker and Python 3. The harness builds the pinned container and runs every PostgreSQL example:
git clone https://github.com/qnixon/dswithx.git
cd dswithx
python3 harness/run_tests.py --language postgresql