Skip to content

Commit

Permalink
Update sql for v_export_bal
Browse files Browse the repository at this point in the history
  • Loading branch information
pdrillin committed Aug 24, 2021
1 parent f90333a commit 97b2e9b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 89 deletions.
43 changes: 6 additions & 37 deletions gestion_base_adresse/install/sql/adresse/30_VIEW.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ CREATE VIEW adresse.v_export_bal AS
g.id AS cad_parcelles,
c.commune_nom AS source,
p.date_modif AS date_der_maj
FROM adresse.commune c,
adresse.commune_deleguee cd,
adresse.point_adresse p,
adresse.voie v,
adresse.parcelle g
WHERE ((p.id_commune = c.id_com) AND public.st_intersects(cd.geom, p.geom) AND public.st_intersects(g.geom, p.geom) AND (p.id_voie = v.id_voie))
FROM ((((adresse.point_adresse p
LEFT JOIN adresse.commune_deleguee cd ON (public.st_intersects(cd.geom, p.geom)))
LEFT JOIN adresse.commune c ON ((p.id_commune = c.id_com)))
LEFT JOIN adresse.voie v ON ((p.id_voie = v.id_voie)))
LEFT JOIN adresse.parcelle g ON (public.st_intersects(g.geom, p.geom)))
UNION
SELECT ''::text AS uid_adresse,
concat(c.insee_code, '_', 'xxxx', '_', ld.numero) AS cle_interop,
Expand All @@ -79,37 +78,7 @@ UNION
FROM ((adresse.lieux_dits ld
LEFT JOIN adresse.commune_deleguee cd ON ((cd.id_com_del = ld.id_com_del)))
LEFT JOIN adresse.commune c ON ((c.id_com = ld.id_com)))
WHERE (ld.integration_ban = true)
UNION
SELECT ''::text AS uid_adresse,
CASE
WHEN ((p.suffixe IS NOT NULL) AND (v.code_fantoir IS NOT NULL)) THEN concat(c.insee_code, '_', (v.code_fantoir)::text, '_', lpad((p.numero)::text, 5, '0'::text), '_', p.suffixe)
WHEN ((p.suffixe IS NULL) AND (v.code_fantoir IS NULL)) THEN concat(c.insee_code, '_', 'xxxx', '_', lpad((p.numero)::text, 5, '0'::text))
WHEN ((p.suffixe IS NULL) AND (v.code_fantoir IS NOT NULL)) THEN concat(c.insee_code, '_', (v.code_fantoir)::text, '_', lpad((p.numero)::text, 5, '0'::text))
WHEN ((p.suffixe IS NOT NULL) AND (v.code_fantoir IS NULL)) THEN concat(c.insee_code, '_', 'xxxx', '_', lpad((p.numero)::text, 5, '0'::text), '_', p.suffixe)
ELSE NULL::text
END AS cle_interop,
c.insee_code AS commune_insee,
c.commune_nom,
cd.insee_code AS commune_deleguee_insee,
cd.commune_deleguee_nom,
v.nom_complet AS voie_nom,
p.lieudit_complement_nom,
p.numero,
p.suffixe,
p.type_pos AS "position",
public.st_x(p.geom) AS x,
public.st_y(p.geom) AS y,
round((public.st_x(public.st_transform(p.geom, 4326)))::numeric, 10) AS long,
round((public.st_y(public.st_transform(p.geom, 4326)))::numeric, 10) AS lat,
''::text AS cad_parcelles,
c.commune_nom AS source,
p.date_modif AS date_der_maj
FROM adresse.commune c,
adresse.commune_deleguee cd,
adresse.point_adresse p,
adresse.voie v
WHERE ((p.id_parcelle IS NULL) AND (p.id_commune = c.id_com) AND (p.id_voie = v.id_voie) AND public.st_intersects(cd.geom, p.geom));
WHERE (ld.integration_ban = true);


-- v_point_adresse
Expand Down
73 changes: 21 additions & 52 deletions gestion_base_adresse/install/sql/upgrade/upgrade_to_0.8.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,10 @@ DROP VIEW IF EXISTS adresse.v_export_bal;
CREATE VIEW adresse.v_export_bal AS
SELECT ''::text AS uid_adresse,
CASE
WHEN ((p.suffixe IS NOT NULL) AND (v.code_fantoir IS NOT NULL)) THEN concat(c.insee_code, '_', (v.code_fantoir)::text, '_', lpad((p.numero)::text, 5, '0'::text), '_', p.suffixe)
WHEN ((p.suffixe IS NULL) AND (v.code_fantoir IS NULL)) THEN concat(c.insee_code, '_', 'xxxx', '_', lpad((p.numero)::text, 5, '0'::text))
WHEN ((p.suffixe IS NULL) AND (v.code_fantoir IS NOT NULL)) THEN concat(c.insee_code, '_', (v.code_fantoir)::text, '_', lpad((p.numero)::text, 5, '0'::text))
WHEN ((p.suffixe IS NOT NULL) AND (v.code_fantoir IS NULL)) THEN concat(c.insee_code, '_', 'xxxx', '_', lpad((p.numero)::text, 5, '0'::text), '_', p.suffixe)
WHEN p.suffixe IS NOT NULL AND v.code_fantoir IS NOT NULL THEN concat(c.insee_code, '_', v.code_fantoir::text, '_', lpad(p.numero::text, 5, '0'::text), '_', p.suffixe)
WHEN p.suffixe IS NULL AND v.code_fantoir IS NULL THEN concat(c.insee_code, '_', 'xxxx', '_', lpad(p.numero::text, 5, '0'::text))
WHEN p.suffixe IS NULL AND v.code_fantoir IS NOT NULL THEN concat(c.insee_code, '_', v.code_fantoir::text, '_', lpad(p.numero::text, 5, '0'::text))
WHEN p.suffixe IS NOT NULL AND v.code_fantoir IS NULL THEN concat(c.insee_code, '_', 'xxxx', '_', lpad(p.numero::text, 5, '0'::text), '_', p.suffixe)
ELSE NULL::text
END AS cle_interop,
c.insee_code AS commune_insee,
Expand All @@ -502,19 +502,18 @@ CREATE VIEW adresse.v_export_bal AS
p.numero,
p.suffixe,
p.type_pos AS "position",
public.st_x(p.geom) AS x,
public.st_y(p.geom) AS y,
round((public.st_x(public.st_transform(p.geom, 4326)))::numeric, 10) AS long,
round((public.st_y(public.st_transform(p.geom, 4326)))::numeric, 10) AS lat,
st_x(p.geom) AS x,
st_y(p.geom) AS y,
round(st_x(st_transform(p.geom, 4326))::numeric, 10) AS long,
round(st_y(st_transform(p.geom, 4326))::numeric, 10) AS lat,
g.id AS cad_parcelles,
c.commune_nom AS source,
p.date_modif AS date_der_maj
FROM adresse.commune c,
adresse.commune_deleguee cd,
adresse.point_adresse p,
adresse.voie v,
adresse.parcelle g
WHERE ((p.id_commune = c.id_com) AND public.st_intersects(cd.geom, p.geom) AND public.st_intersects(g.geom, p.geom) AND (p.id_voie = v.id_voie))
FROM adresse.point_adresse p
LEFT JOIN adresse.commune_deleguee cd ON (st_intersects(cd.geom, p.geom))
LEFT JOIN adresse.commune c ON (p.id_commune = c.id_com)
LEFT JOIN adresse.voie v ON (p.id_voie = v.id_voie)
LEFT JOIN adresse.parcelle g ON (st_intersects(g.geom, p.geom))
UNION
SELECT ''::text AS uid_adresse,
concat(c.insee_code, '_', 'xxxx', '_', ld.numero) AS cle_interop,
Expand All @@ -527,47 +526,17 @@ UNION
ld.numero,
''::text AS suffixe,
''::text AS "position",
public.st_x(ld.geom) AS x,
public.st_y(ld.geom) AS y,
round((public.st_x(public.st_transform(ld.geom, 4326)))::numeric, 10) AS long,
round((public.st_y(public.st_transform(ld.geom, 4326)))::numeric, 10) AS lat,
st_x(ld.geom) AS x,
st_y(ld.geom) AS y,
round(st_x(st_transform(ld.geom, 4326))::numeric, 10) AS long,
round(st_y(st_transform(ld.geom, 4326))::numeric, 10) AS lat,
''::text AS cad_parcelles,
ld.commune_nom AS source,
ld.date_der_maj
FROM ((adresse.lieux_dits ld
LEFT JOIN adresse.commune_deleguee cd ON ((cd.id_com_del = ld.id_com_del)))
LEFT JOIN adresse.commune c ON ((c.id_com = ld.id_com)))
WHERE (ld.integration_ban = true)
UNION
SELECT ''::text AS uid_adresse,
CASE
WHEN ((p.suffixe IS NOT NULL) AND (v.code_fantoir IS NOT NULL)) THEN concat(c.insee_code, '_', (v.code_fantoir)::text, '_', lpad((p.numero)::text, 5, '0'::text), '_', p.suffixe)
WHEN ((p.suffixe IS NULL) AND (v.code_fantoir IS NULL)) THEN concat(c.insee_code, '_', 'xxxx', '_', lpad((p.numero)::text, 5, '0'::text))
WHEN ((p.suffixe IS NULL) AND (v.code_fantoir IS NOT NULL)) THEN concat(c.insee_code, '_', (v.code_fantoir)::text, '_', lpad((p.numero)::text, 5, '0'::text))
WHEN ((p.suffixe IS NOT NULL) AND (v.code_fantoir IS NULL)) THEN concat(c.insee_code, '_', 'xxxx', '_', lpad((p.numero)::text, 5, '0'::text), '_', p.suffixe)
ELSE NULL::text
END AS cle_interop,
c.insee_code AS commune_insee,
c.commune_nom,
cd.insee_code AS commune_deleguee_insee,
cd.commune_deleguee_nom,
v.nom_complet AS voie_nom,
p.lieudit_complement_nom,
p.numero,
p.suffixe,
p.type_pos AS "position",
public.st_x(p.geom) AS x,
public.st_y(p.geom) AS y,
round((public.st_x(public.st_transform(p.geom, 4326)))::numeric, 10) AS long,
round((public.st_y(public.st_transform(p.geom, 4326)))::numeric, 10) AS lat,
''::text AS cad_parcelles,
c.commune_nom AS source,
p.date_modif AS date_der_maj
FROM adresse.commune c,
adresse.commune_deleguee cd,
adresse.point_adresse p,
adresse.voie v
WHERE ((p.id_parcelle IS NULL) AND (p.id_commune = c.id_com) AND (p.id_voie = v.id_voie) AND public.st_intersects(cd.geom, p.geom));
FROM adresse.lieux_dits ld
LEFT JOIN adresse.commune_deleguee cd ON cd.id_com_del = ld.id_com_del
LEFT JOIN adresse.commune c ON c.id_com = ld.id_com
WHERE ld.integration_ban = true;

ALTER VIEW IF EXISTS adresse.vue_com RENAME TO v_commune;

Expand Down

0 comments on commit 97b2e9b

Please sign in to comment.