forked from sqldelight/sqldelight
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix 5345 PostgreSql SELECT DISTINCT ON (sqldelight#5353)
* Update DistinctOnExpressionMixin.kt Update DistinctOnExpressionMixin.kt - expose missing tables Query the columns or any tables prefixing columns in the distinctOn clause As there could be one or more columns with the same table prefix, remove any duplicates * Add tests fixture tests - multiple tables and columns in DISTINCT ON integration test - valid sql is generated and helps prevent regressions * Remove unnecessary nullability As the code is was using mapNotNull Remove unnecessary null type parameter and not-null assertion operator
- Loading branch information
Showing
5 changed files
with
90 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
6 changes: 3 additions & 3 deletions
6
.../postgresql/src/testFixtures/resources/fixtures_postgresql/select-distinct-on/failure.txt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Test.s line 33:9 - SELECT DISTINCT ON expressions must match initial ORDER BY expressions | ||
Test.s line 38:9 - SELECT DISTINCT ON expressions must match initial ORDER BY expressions | ||
Test.s line 43:15 - SELECT DISTINCT ON expressions must match initial ORDER BY expressions | ||
Test.s line 43:9 - SELECT DISTINCT ON expressions must match initial ORDER BY expressions | ||
Test.s line 48:9 - SELECT DISTINCT ON expressions must match initial ORDER BY expressions | ||
Test.s line 53:15 - SELECT DISTINCT ON expressions must match initial ORDER BY expressions |
29 changes: 29 additions & 0 deletions
29
...n-postgresql/src/main/sqldelight/app/cash/sqldelight/postgresql/integration/DistinctOn.sq
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
CREATE TABLE student( | ||
student_id INTEGER PRIMARY KEY, | ||
name TEXT NOT NULL | ||
); | ||
|
||
CREATE TABLE grade( | ||
grade_id INTEGER PRIMARY KEY, | ||
student_id INTEGER REFERENCES student(student_id), | ||
grade INT NOT NULL, | ||
grade_date TIMESTAMP NOT NULL | ||
); | ||
|
||
insertStudent: | ||
INSERT INTO student VALUES ?; | ||
|
||
insertGrade: | ||
INSERT INTO grade VALUES ?; | ||
|
||
selectDistinctOnStudent: | ||
SELECT DISTINCT ON (student_id) * | ||
FROM grade | ||
JOIN student USING (student_id) | ||
ORDER BY student_id, grade_date; | ||
|
||
selectDistinctOnStudentGradeDate: | ||
SELECT DISTINCT ON (grade.student_id, grade.grade_date) grade.*, student.* | ||
FROM grade | ||
JOIN student USING (student_id) | ||
ORDER BY grade.student_id, grade_date; |
This file contains 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