Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 5086 PostgreSql Right Full Join #5136

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

griffio
Copy link
Contributor

@griffio griffio commented Apr 8, 2024

Fixes #5086

AlecKazakova/sql-psi#616 is now included in SqlDelight dependency

  • Added Postgresql grammar- must override join_operator inherited from sql-psi to include join rules
  • Added Fixture tests for joins (checked in psql)
SELECT *
FROM A
FULL OUTER JOIN B ON A.id = B.a_id
LEFT JOIN C ON A.id = C.a_id
RIGHT JOIN D ON B.id = D.b_id;

Maybe add integration test?
TODO
Add compiler test to check that RIGHT and FULL allow same as LEFT joins with nullable results https://github.com/cashapp/sqldelight/blob/master/sqldelight-compiler/src/test/kotlin/app/cash/sqldelight/core/queries/InterfaceGeneration.kt
See for nullabilty https://github.com/AlecKazakova/sql-psi/blob/4f9478e3f41f221d0ea59dcf8da6d53ee1c8c6f2/core/src/main/kotlin/com/alecstrong/sql/psi/core/psi/mixins/JoinClauseMixin.kt#L67

@AlecKazakova
Copy link
Collaborator

i think it would be good to add a test in the compiler tests to verify the generated code looks like what you want it to. You can specify a test to run only against a certain dialect like this

@griffio
Copy link
Contributor Author

griffio commented Apr 8, 2024

🔕 Don't think it's quite correct, as only left joins currently produce nullable types on the B table interface
given,

SELECT *
FROM A LEFT JOIN B USING (id);

LEFT JOINS nulls on right expected and does so in table data interface

id val1 val2
1 a null
2 b null
SELECT *
FROM A RIGHT JOIN B USING (id);

RIGHT JOINS nulls on left side expected, doesn't have nullable types for A fields

id val1 val2
11 null a
21 null b
SELECT *
FROM A FULL JOIN B USING (id);

FULL JOINS nulls on both sides expected, doesn't have nullable types for A, B fields

id val1 val2
1 a null
2 b null
11 null a
21 null b

Maybe not surprising since the current code is not going to handle RIGHT and FULL nullability...I will need to investigate 🔍

Copy link
Collaborator

@AlecKazakova AlecKazakova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, will rereview once thats been added

i suspect it may now involve sql-psi changes, as the logic around join nullability is there: https://github.com/AlecKazakova/sql-psi/blob/master/core/src/main/kotlin/com/alecstrong/sql/psi/core/psi/mixins/JoinClauseMixin.kt#L66-L69

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for pg RIGHT/FULL [OUTER] JOIN
2 participants