This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| drop table if exists users; | |
| create table users ( | |
| user_id int primary key, | |
| username varchar(50) not null, | |
| last_review_ts datetime not null | |
| ); | |
| insert into users (user_id, username, last_review_ts) | |
| values | |
| (1, 'Alex', '2023-12-01 10:00:00'), | |
| (2, 'Blake', '2024-01-20 21:30:00'), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| SQL's GROUPS BETWEEN alternative | |
| Bill Wallis, 2025-08-05 | |
| */ | |
| drop table if exists trials; | |
| create table trials ( | |
| trial_id int, | |
| trial_date date, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| SQL's RANGE BETWEEN alternative | |
| Bill Wallis, 2025-08-02 | |
| */ | |
| drop table if exists events; | |
| create table events ( | |
| event_id int primary key, | |
| user_id int not null, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # /// script | |
| # dependencies = [ | |
| # "duckdb>=1.3.1", | |
| # "sqlglot[rs]>=27.2.0", | |
| # ] | |
| # /// | |
| import duckdb | |
| import sqlglot | |
| import sqlglot.optimizer.qualify |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Moving logic to data | |
| DuckDB version: v1.3.1 | |
| Bill Wallis, 2025-07-24 | |
| */ | |
| select version(); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Using FILTER in a window (OVER) | |
| PostgreSQL version: 16.2 | |
| Bill Wallis, 2025-05-12 | |
| */ | |
| drop table if exists events; | |
| create table events ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/your-path-to/.local/bin/uv run --script | |
| # /// script | |
| # requires-python = ">=3.11" | |
| # dependencies = [ | |
| # "wakepy", | |
| # ] | |
| # /// | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| DuckDB cross-data-source query | |
| DuckDB version: v1.3.2 | |
| Bill Wallis, 2024-12-15 | |
| This is just for illustration: the files are purposefully not included in this Gist | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| id | col_1 | col_2 | col_3 | |
|---|---|---|---|---|
| 1 | a | b | 0.1 | |
| 2 | c | d | -11 | |
| 3 | e | f | 111 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 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 | |
| ) |
NewerOlder