Skip to content

Instantly share code, notes, and snippets.

View billwallis's full-sized avatar
🧙
Mathemagicianing

Bill billwallis

🧙
Mathemagicianing
View GitHub Profile
@billwallis
billwallis / filter-over.sql
Created May 12, 2025 06:51
Using FILTER in a window (OVER)
/*
Using FILTER in a window (OVER)
PostgreSQL version: 16.2
Bill Wallis, 2025-05-12
*/
drop table if exists events;
create table events (
@billwallis
billwallis / keep-awake
Created April 15, 2025 10:20
Keep screen awake script using wakepy and uv
#!/your-path-to/.local/bin/uv run --script
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "wakepy",
# ]
# ///
"""
@billwallis
billwallis / duckdb-cross-data-source-query.sql
Last active January 26, 2025 21:16
DuckDB cross-data-source query
/*
DuckDB cross-data-source query
DuckDB version: v1.1.1
Bill Wallis, 2024-12-15
This is just for illustration: the files are purposefully not included in this Gist
*/
@billwallis
billwallis / csv-1.csv
Created December 4, 2024 09:29
DuckDB CSV diff
id col_1 col_2 col_3
1 a b 0.1
2 c d -11
3 e f 111
@billwallis
billwallis / connect-by-oracle.sql
Last active October 21, 2024 07:03
Recursive CTEs for graph traversal
/* flatten bus route */
with bus_stops(from_stop, to_stop) as (
select 'BM', 'WQS' from dual
union all select 'CR', 'BM' from dual
union all select 'CS', 'LL' from dual
union all select 'GG', 'CS' from dual
union all select 'LL', 'OS' from dual
union all select 'OS', 'CR' from dual
union all select 'WQS', 'GG' from dual
)
@billwallis
billwallis / recursive-ctes-data-generation.sql
Created October 18, 2024 05:56
Recursive CTEs for data generation
/*
Recursive CTEs for data generation
DuckDB version: 1.0.0
Bill Wallis, 2024-10-18
*/
select version();
@billwallis
billwallis / SQL tuple filter performance
Last active September 3, 2024 09:01
SQL tuple filter performance
Creating tables...
Timing SQLite queries...
Start time: 2024-08-31 09:23:05.697240
----------------------------------------
100%|██████████| 10000/10000 [00:02<00:00, 3370.72it/s]
query-1.sql: 0.00008558s (50.1%)
query-2.sql: 0.00008527s (49.9%)
----------------------------------------
End time: 2024-08-31 09:23:08.676550
@billwallis
billwallis / rollup.sql
Created August 4, 2024 10:43
Using ROLLUP for subtotals
/*
Using ROLLUP for subtotals
DuckDB version: 1.0.0
Bill Wallis, 2024-08-04
*/
select version();
@billwallis
billwallis / window-clause.sql
Created August 2, 2024 19:48
The WINDOW clause needs some more love
/*
The WINDOW clause needs some more love
DuckDB version: 1.0.0
Bill Wallis, 2024-08-02
*/
select version();
/*
SQL Indexes (specifically SQLite)
SQLite version: 3.45.1
Bill Wallis, 2024-07-27
https://sqlite.org/queryplanner.html
https://use-the-index-luke.com/
*/