Full Join with partitions in PostgreSQL
postgresql, sql
Published on 2017-02-26 | Jeremy Greze
On a deux tables avec une colonne qui partitionne les données, par exemple une colonne date
au format YYYY-MM-DD.
On souhaite joindre les deux tables exhaustivement (FULL OUTER JOIN
) mais de façon à conserver notre partitionnement et avec une condition (correpondance d'un id par exemple).
select
COALESCE("input1"."date", "input2"."date") as "date",
-- ...
-- for example:
"input1"."my_id" IS NOT NULL AS "exist_in_input1",
"input2"."my_id" IS NOT NULL AS "exist_in_input2",
COALESCE("input1"."my_id", "input2"."my_id") AS "my_id",
from "input1"
full outer join "input2"
"input1"."my_id" = "input2"."my_id" -- just an example
and
"input1"."date" = "input2"."date"
where -- if you want to build only one partition
"input1"."date" = '2017-02-26' or "input2"."date" = '2017-02-26'
C'est un exemple ici avec PostgreSQL. Mais cela ne marche pas avec MySQL.