## Quick Tip: How to Extract a Month as an int in PaDB

select extract(month from ds)::int
from cool_db_name.cool_table limit 10;

## Postgres / PaDB: Statistics

 `corr(Y, X)` double precision double precision correlation coefficient `covar_pop(Y, X)` double precision double precision population covariance `covar_samp(Y, X)` double precision double precision sample covariance `regr_avgx(Y, X)` double precision double precision average of the independent variable (sum(X)/N) `regr_avgy(Y, X)` double precision double precision average of the dependent variable (sum(Y)/N) `regr_count(Y, X)` double precision bigint number of input rows in which both expressions are nonnull `regr_intercept(Y, X)` double precision double precision y-intercept of the least-squares-fit linear equation determined by the (X, Y) pairs `regr_r2(Y, X)` double precision double precision square of the correlation coefficient `regr_slope(Y, X)` double precision double precision slope of the least-squares-fit linear equation determined by the (X, Y) pairs `regr_sxx(Y, X)` double precision double precision sum(X^2) – sum(X)^2/N (“sum of squares” of the independent variable) `regr_sxy(Y, X)` double precision double precision sum(X*Y) – sum(X) * sum(Y)/N (“sum of products” of independent times dependent variable) `regr_syy(Y, X)` double precision double precision sum(Y^2) – sum(Y)^2/N (“sum of squares” of the dependent variable) `stddev(expression)` smallint, int, bigint, real, double precision, or numeric double precision for floating-point arguments, otherwise numeric historical alias for `stddev_samp` `stddev_pop(expression)` smallint, int, bigint, real, double precision, or numeric double precision for floating-point arguments, otherwise numeric population standard deviation of the input values `stddev_samp(expression)` smallint, int, bigint, real, double precision, or numeric double precision for floating-point arguments, otherwise numeric sample standard deviation of the input values `variance`(expression) smallint, int, bigint, real, double precision, or numeric double precision for floating-point arguments, otherwise numeric historical alias for `var_samp` `var_pop`(expression) smallint, int, bigint, real, double precision, or numeric double precision for floating-point arguments, otherwise numeric population variance of the input values (square of the population standard deviation) `var_samp`(expression) smallint, int, bigint, real, double precision, or numeric double precision for floating-point arguments, otherwise numeric sample variance of the input values (square of the sample standard deviation)

## Quick Tip: Check PaDB Disk Usage in 1 Line

select owner, host, diskno, used, capacity from stv_partitions order by 1, 2, 3, 4, 5;
or
select sum( used), sum(capacity) from stv_partitions;

## Quick Tip: Create a Binary Column Conditionally in Postgres/PaDB/SQL

``````
create table c as
select a.id, tall, funny, weight,
(case when b.id is null then 0 else 1 end) as rich
from tablea a left outer join
tableb b ``````
`         on a.id = b.id;`
or
``````select
a.id, tall, funny, weight,
(b.id is not null)::integer as rich
from
tablea a
left outer join``````
`    tableb b on a.id = b.id`

## Quick-Tip: Connect to a ParAccell (aka PaDB) DB from Bash in 1 Line

psql -h xen-01.yourhostname.com –username paraccel hsa -p 5439