J'ai créé une table via une requête sur Pgadmin. J'aimerai pouvoir la mettre à jour (via exactement la même requête) sans avoir à recréer la table en l'écrasant à chaque fois (car la table est utilisée dans des applications).
Pour cela je voudrais utiliser un Truncate pour vider puis un Update pour la remplir mais ma requête de base étant un peu complexe, je n'arrive pas à adapter ce Update pour qu'il fonctionne (pas possible de mettre de Group By ou de row_number notamment)
Voici le code utilisé qui créé la table et que je veux adapter à un Update :
Code : Tout sélectionner
CREATE TABLE comptage.tab_comptage
AS
SELECT row_number() OVER ()::integer AS objectid,
centrale.libelle AS nom_voie,
publication.id_centrale,
publication.code_centrale,
publication.id_canal,
publication.code_canal,
publication.libelle_groupage,
date_part('year'::text, publication.horodate)::text AS annee,
publication.horodate,
publication.descriptif_periode,
sum(( SELECT publication.valeur::integer AS valeur
WHERE publication.type_mesure::text = 'HP_JOHVS_matin'::text)) AS hp_johvs_matin,
sum(( SELECT publication.valeur::integer AS valeur
WHERE publication.type_mesure::text = 'HP_JOHVS_soir'::text)) AS hp_johvs_soir,
sum(( SELECT publication.valeur::integer AS valeur
WHERE publication.type_mesure::text = 'MJA_JO'::text)) AS mja_jo,
sum(( SELECT publication.valeur::integer AS valeur
WHERE publication.type_mesure::text = 'MJA_TCJ'::text)) AS mja_tcj,
sum(( SELECT publication.valeur::integer AS valeur
WHERE publication.type_mesure::text = 'TIR_TCJ'::text)) AS tir_tcj,
sum(( SELECT publication.valeur::integer AS valeur
WHERE publication.type_mesure::text = 'V85MA_TCJ'::text)) AS v85ma_tcj,
sum(( SELECT publication.valeur::integer AS valeur
WHERE publication.type_mesure::text = 'VTMA_TCJ'::text)) AS vtma_tcj,
sum(( SELECT publication.valeur::integer AS valeur
WHERE publication.type_mesure::text = 'MJA_PL_TCJ'::text)) AS mja_pl_tcj
FROM publication,
centrale
WHERE publication.id_centrale = centrale.id_centrale
GROUP BY publication.id_centrale, publication.code_centrale, publication.id_canal, publication.code_canal, publication.libelle_groupage, publication.horodate, publication.descriptif_periode, centrale.libelle;