Skip to content

Latest commit

 

History

History
162 lines (109 loc) · 2.86 KB

File metadata and controls

162 lines (109 loc) · 2.86 KB
marp true
title SQL in the shell
description Relationenalgebra auf der Kommandozeile
theme terminal
paginate true
_paginate false
class invert

SQL in the shell

Relationenalgebra auf der Kommandozeile


Relation

id name stadt
1 Mueller GmbH Berlin
2 Schmidt AG Hamburg
  • Attribut: Spalte (id, name, stadt)
  • Tupel: Zeile (1, Mueller GmbH, Berlin)

Operationen

  • Projektion
  • Selektion
  • Vereinigung
  • Differenz
  • Umbenennung
  • Kartesisches Produkt

Projektion

$$ R = \text{Relation über} {A_1, …, A_k} \text{ und }β ⊆ {A_1, …, A_k}. $$

$$ \pi_{\beta}(R):={t_{\beta}|t \in R} $$


Selektion

$$ \sigma_{\text{A}}(R) := { t | t \in R \wedge t \text{ erf"ullt A} } $$

SELECT * FROM Customers
    WHERE Country LIKE '%ada%';

Vereinigung

$$ R \cup S := { t | t \in R \lor t \in S } $$

SELECT * FROM Customers_A
    UNION
        SELECT * FROM Customers_B;

Differenz

$$ R \setminus S := { t | t \in R \land t \notin S } $$

SELECT * FROM Customers_A
    EXCEPT
        SELECT * FROM Customers_B;

Umbenennung

$$ \rho_{[\mathrm{neu}\leftarrow\mathrm{alt}]}(R):= {t'|t'(R-\mathrm{alt})=t(R-\mathrm{alt}) \land t'(\mathrm{neu})=t(\mathrm{alt})} $$

awk -F ',' '{print $2, $1}' R

Kartesisches Produkt

$$ R\times S:={(a_1,a_2,...,a_n,b_1,b_2,...,b_m)| \\ (a_1,...,a_n)\in R\wedge (b_1,...,b_m)\in S} $$

SELECT * FROM R, S;

Join?

Kartesisches Produkt Selektion Projektion


Revue

  • cat: Vereinigung
  • grep: Selektion
  • awk: Selektion, Projektion, Umbenennung
  • comm: Differenz

Unix Tools

cat · sed · grep · cut · awk · join · comm · diff · uniq · sort

"Do one thing and do it well"


Inspiration

"Relational algebra can turn any shell into a respectable database."

Matt Might - SQL in the Shell


w:150

Danke!

Martin Funk · @eigenfunk

github.com/eigenfunk/sql-in-the-shell