gis
Database
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
insert_import_veloroutes_itineraire
Parameters
Name
Type
Mode
idimport
integer
IN
Definition
DECLARE id_veloroutes integer; BEGIN INSERT INTO veloroutes.itineraire( site_web, numero, nom_usage, nom_officiel, niveau_schema, est_inscrit, depart, arrivee, annee_inscription, annee_subv, mont_subv, annee_ouverture) SELECT site_web, numero, nom_usage, nom_officiel, CASE WHEN EXISTS (SELECT 1 FROM veloroutes.niveau_administratif_val WHERE UPPER(code) = UPPER(niveau_schema)) THEN niveau_schema WHEN EXISTS (SELECT 1 FROM veloroutes.niveau_administratif_val WHERE UPPER(libelle) = UPPER(niveau_schema)) THEN (SELECT code FROM veloroutes.niveau_administratif_val as v WHERE UPPER(v.libelle) = UPPER(niveau_schema) LIMIT 1) ELSE niveau_schema END AS niveau_schema, CASE WHEN EXISTS (SELECT 1 FROM veloroutes.booleen_val WHERE UPPER(code) = UPPER(est_inscrit)) THEN est_inscrit WHEN EXISTS (SELECT 1 FROM veloroutes.booleen_val WHERE UPPER(libelle) = UPPER(est_inscrit)) THEN (SELECT code FROM veloroutes.booleen_val as v WHERE UPPER(v.libelle) = UPPER(est_inscrit) LIMIT 1) --WHEN est_inscrit = 'non' THEN 'F' --WHEN est_inscrit = 'oui' THEN 'T' ELSE est_inscrit END AS est_inscrit, depart, arrivee, CASE WHEN substring(annee_inscription from 1 for 10) LIKE '__-__-____' THEN to_date(substring(annee_inscription from 1 for 10),'DD-MM-YYYY') WHEN substring(annee_inscription from 1 for 10) LIKE '__/__/____' THEN to_date(substring(annee_inscription from 1 for 10),'DD-MM-YYYY') END AS annee_inscription, CAST (annee_subv as integer), CAST (mont_subv AS real), CASE WHEN substring(annee_ouverture from 1 for 10) LIKE '__-__-____' THEN to_date(substring(annee_ouverture from 1 for 10),'DD-MM-YYYY') WHEN substring(annee_ouverture from 1 for 10) LIKE '__/__/____' THEN to_date(substring(annee_ouverture from 1 for 10),'DD-MM-YYYY') END AS annee_ouverture FROM imports.import_itineraire as ii WHERE ii.id_import = idimport RETURNING id_iti into id_veloroutes; RETURN id_veloroutes; END;