PostgreSQL: FULL OUTER JOIN with partitioned tables

Dataiker, Alpha Tester Posts: 535 Dataiker
I have 2 datasets (PostgreSQL) to join: "input1", "input2" and the result should be "output".
All datasets are partitioned by date.

How to make a FULL OUTER JOIN and keep the partition?

Answers

  • Alpha Tester, Dataiker Alumni Posts: 190 ✭✭✭✭✭✭✭✭
    edited July 2024

    Here it is (with the partition named "date"):


    select
    COALESCE("input1"."date", "input2"."date") as "date",
    ...

    from "input1"
    full outer join "input2"
    ... and "input1"."date" = "input2"."date"

    where
    "input1"."date" = '$DKU_DST_date' or "input2"."date" = '$DKU_DST_date'

  • Dataiker Alumni Posts: 87 ✭✭✭✭✭✭✭
    Side note: since it's an OUTER join, SQL keeps all lines from both datasets, even ones that don't match the ON clause, putting NULL values in columns from the other dataset. So adding a condition like "date" = '$DKU_DST_date' in the ON clause does not works, one needs to add it in the WHERE clause.

Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.