Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/griffio/sqldelight-postgres-lateral-join
SqlDelight PostgreSql Lateral Joins
https://github.com/griffio/sqldelight-postgres-lateral-join
kotlin lateral postgresql sqldelight
Last synced: 5 days ago
JSON representation
SqlDelight PostgreSql Lateral Joins
- Host: GitHub
- URL: https://github.com/griffio/sqldelight-postgres-lateral-join
- Owner: griffio
- Created: 2024-09-14T14:01:45.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2024-12-06T10:59:29.000Z (18 days ago)
- Last Synced: 2024-12-06T11:33:41.407Z (18 days ago)
- Topics: kotlin, lateral, postgresql, sqldelight
- Language: Kotlin
- Homepage:
- Size: 62.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SqlDelight 2.1.x Postgresql Lateral Joins
https://github.com/cashapp/sqldelight
Snapshot version: 2.1.0-SNAPSHOT
Initial support for lateral joins https://github.com/cashapp/sqldelight/pull/5337
Not supported: Lateral joins on table expressions e.g json, arrays, sets, generate_series
```sql
SELECT
pledged_usd,
avg_pledge_usd,
duration,
(usd_from_goal / duration) AS usd_needed_daily
FROM Kickstarter_Data,
LATERAL (SELECT pledged / NULLIF(fx_rate, 0) AS pledged_usd) pu,
LATERAL (SELECT pledged_usd / NULLIF(backers_count, 0) AS avg_pledge_usd) apu,
LATERAL (SELECT goal / NULLIF(fx_rate, 0) AS goal_usd) gu,
LATERAL (SELECT goal_usd - pledged_usd AS usd_from_goal) ufg,
LATERAL (SELECT (deadline - launched_at) / 86400.00 AS duration) dr;
``````sql
SELECT
sp.id salesperson_id,
sp.full_name,
sp.home_region_id,
rg.name AS home_region_name,
home_region_sales.total_sales
FROM SalesPeople sp
JOIN Regions rg ON sp.home_region_id = rg.id
JOIN LATERAL (
SELECT SUM(amount) AS total_sales
FROM Sales s
WHERE s.salesperson_id = sp.id
AND s.region_id = sp.home_region_id
) home_region_sales ON TRUE;
```
----```shell
createdb laterals &&
./gradlew build &&
./gradlew flywayMigrate
```Flyway db migrations
https://documentation.red-gate.com/fd/gradle-task-184127407.html