sqldelight icon indicating copy to clipboard operation
sqldelight copied to clipboard

Add 5086 PostgreSql Right Full Join

Open griffio opened this issue 1 year ago • 2 comments

Fixes #5086

https://github.com/AlecKazakova/sql-psi/pull/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

griffio avatar Apr 08 '24 06:04 griffio

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

AlecKazakova avatar Apr 08 '24 14:04 AlecKazakova

🔕 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 🔍

griffio avatar Apr 08 '24 18:04 griffio