Partitions

2 snippets across 2 stacks — Bash & Linux, SQL

Also written as partition by

SHBash & Linux

List Block Devices

SH · System Info
syntax
lsblk [options]
example
lsblk -f
output
NAME   FSTYPE  LABEL   SIZE MOUNTPOINT
sda                    100G
├─sda1 ext4   root     50G /
├─sda2 swap            4G  [SWAP]
└─sda3 xfs    data    46G  /data

Note -f shows filesystem type, label, UUID, and mount points. Useful for identifying disks before mounting or partitioning. Linux only; on macOS, use diskutil list.

SQLSQL

PARTITION BY

SQL · Window Functions
syntax
window_function() OVER (PARTITION BY column ORDER BY column)
example
SELECT
  department_id,
  first_name,
  salary,
  ROW_NUMBER() OVER (
    PARTITION BY department_id
    ORDER BY salary DESC
  ) AS dept_rank
FROM employees;
output
-- department_id | first_name | salary | dept_rank
-- 1             | Alice      | 95000  | 1
-- 1             | Bob        | 82000  | 2
-- 2             | Carol      | 105000 | 1
-- 2             | Dave       | 78000  | 2

Note PARTITION BY divides rows into groups and applies the window function independently within each group. It is like GROUP BY but without collapsing rows. You can partition by multiple columns.