Skip to content

Commit

Permalink
keep stefan's script
Browse files Browse the repository at this point in the history
(removed from qgepplugin's PR)
  • Loading branch information
olivierdalang committed Apr 22, 2021
1 parent 6277168 commit f667243
Show file tree
Hide file tree
Showing 61 changed files with 5,998 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/stefans_scripts/export/90_refresh_materialized_view.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
REFRESH MATERIALIZED VIEW qgep_od.vw_network_node;
REFRESH MATERIALIZED VIEW qgep_od.vw_network_segment;
10 changes: 10 additions & 0 deletions docs/stefans_scripts/export/91_maincover.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
UPDATE qgep_od.wastewater_structure WS
SET fk_main_cover = structure_cover.co_obj_id
FROM (
SELECT WS.obj_id AS obj_id, min(CO.obj_id) AS co_obj_id
FROM qgep_od.wastewater_structure WS
LEFT JOIN qgep_od.structure_part SP ON SP.fk_wastewater_structure = WS.obj_id
LEFT JOIN qgep_od.cover CO ON SP.obj_id = CO.obj_id
GROUP BY WS.obj_id
) AS structure_cover
WHERE structure_cover.obj_id = WS.obj_id;
3 changes: 3 additions & 0 deletions docs/stefans_scripts/export/92_grant_usage.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GRANT USAGE ON SCHEMA qgep_od TO GROUP qgep;
GRANT USAGE ON SCHEMA qgep_sys TO GROUP qgep;
GRANT USAGE ON SCHEMA qgep_vl TO GROUP qgep;
3 changes: 3 additions & 0 deletions docs/stefans_scripts/export/93_grant_all.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GRANT ALL ON schema qgep_od TO postgres;
GRANT ALL ON schema qgep_sys TO postgres;
GRANT ALL ON schema qgep_vl TO postgres;
3 changes: 3 additions & 0 deletions docs/stefans_scripts/export/check_coordinate_cover.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT
ST_AsText(situation_geometry) as deckelkoordinaten
FROM qgep_od.cover ORDER BY deckelkoordinaten ASC;
3 changes: 3 additions & 0 deletions docs/stefans_scripts/export/check_coordinate_reach_point.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT
ST_AsText(situation_geometry) as hpkoordinaten, obj_id
FROM qgep_od.reach_point ORDER BY hpkoordinaten ASC;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT
ST_AsText(situation_geometry) as abwasserknotenkoordinaten, obj_id
FROM qgep_od.wastewater_node ORDER BY abwasserknotenkoordinaten ASC;
4 changes: 4 additions & 0 deletions docs/stefans_scripts/export/check_length_detail_geometry.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT,
ST_AsText(detail_geometry_geometry) as koordinatendetailgeometrie,
st_length(detail_geometry_geometry) AS length_full, obj_id
FROM qgep_od.wastewater_structure ORDER BY length_full ASC;
4 changes: 4 additions & 0 deletions docs/stefans_scripts/export/check_length_reach.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT
ST_AsText(progression_geometry) as koordinaten,
st_length(progression_geometry) AS length_full, obj_id
FROM qgep_od.reach ORDER BY length_full ASC;
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
-- this file generates a new SQL function to create TIDs for all the tables of the import/export schema with ili2pg.
-- you need to set the current maxvalue of the TID into the schema.table.field sia405_abwasser_2015_2_d.t_key_object.t_lastuniqueid
-- questions regarding this function should be directed to Stefan Burckhardt stefan.burckhardt@sjib.ch
-- basis ist tid_generate.sql
-- schema für export heisst abwa_2015neu_3122


-- function for generating TIDs
CREATE OR REPLACE FUNCTION sia405_abwasser_2015_2_d.tid_generate(table_name text, obj_id_table text)
-- RETURNS text AS
RETURNS integer AS
$BODY$
DECLARE
nexttid integer;
newtid integer;
-- myrec_prefix record;
-- myrec_shortcut record;
-- myrec_seq record;
BEGIN
--get sequence for table
-- SELECT nextval('qgep.seq_' || table_name || '_oid') AS seqval INTO myrec_seq;
-- SELECT nextval('sia405_abwasser_2015_2_d.seq_' || table_name || '_tid') AS seqval INTO myrec_seq;
-- 23.12.2015 SELECT t_lastuniqueid FROM sia405_abwasser_2015_2_d.t_key_object AS nexttid;
SELECT t_lastuniqueid INTO nexttid FROM sia405_abwasser_2015_2_d.t_key_object;
newtid = (nexttid + 1);

-- 12.1.2016
RAISE NOTICE 'newtid is %', newtid; -- Print newtid
RAISE NOTICE 'nexttid is %', nexttid; -- Print nexttid

-- adapt t_lastuniqueid in t_key_object
UPDATE sia405_abwasser_2015_2_d.t_key_object
SET t_lastuniqueid = newtid
, t_user = current_user
, t_createdate = current_timestamp
WHERE t_lastuniqueid = nexttid;

IF NOT FOUND THEN
RAISE EXCEPTION 'sequence for table % not found', table_name;
ELSE
RAISE NOTICE 't_key_object updated';
END IF;
-- RETURN myrec_prefix.prefix || myrec_shortcut.shortcut_en || to_char(myrec_seq.seqval,'FM000000');
-- RETURN myrec_prefix.prefix || to_char(myrec_seq.seqval,'FM000000');
RETURN newtid;



END;
$BODY$
-- 12.1.2016 geändert LANGUAGE plpgsql STABLE
LANGUAGE plpgsql VOLATILE
COST 100;
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
-- neu 26.11.2016 Stefan Burckhardt
-- Updates data in sia405_abwasser_2015_2_d.t_ili2db_import_basket with last tid from t_key_object

-- Function: SELECT sia405_abwasser_2015_2_d.basket_update();

DROP FUNCTION IF EXISTS sia405_abwasser_2015_2_d.basket_update();

CREATE OR REPLACE FUNCTION sia405_abwasser_2015_2_d.basket_update()
RETURNS integer AS
$BODY$
DECLARE
lasttid integer;
BEGIN
--get sequence for table
-- SELECT nextval('qgep.seq_' || table_name || '_oid') AS seqval INTO myrec_seq;
-- SELECT nextval('sia405_abwasser_2015_2_d_301.seq_' || table_name || '_tid') AS seqval INTO myrec_seq;

SELECT t_lastuniqueid INTO lasttid FROM sia405_abwasser_2015_2_d.t_key_object;


-- 25.11.2016
RAISE NOTICE '[basket_updtae]: lasttid is %', lasttid; -- Print lasttid


-- adapt t_lastuniqueid in t_key_object
UPDATE sia405_abwasser_2015_2_d.t_ili2db_import_basket
SET t_id = lasttid + 1
, end_t_id = lasttid
, objectcount = lasttid - 2
WHERE import = 2;

IF NOT FOUND THEN
RAISE NOTICE 'sequence for table basket_update not found - first data will be inserted';
INSERT INTO sia405_abwasser_2015_2_d.t_ili2db_import_basket (t_id, import, basket, objectcount, start_t_id, end_t_id) VALUES (lasttid + 1, 2, 3, lasttid - 2, 3, lasttid);

ELSE
RAISE NOTICE 't_ili2db_import_basket updated %', lasttid;
-- SELECT setval (sia405_abwasser_2015_2_d_340.t_ili2db_seq, lasttid + 1);
END IF;
-- RETURN myrec_prefix.prefix || myrec_shortcut.shortcut_en || to_char(myrec_seq.seqval,'FM000000');
-- RETURN myrec_prefix.prefix || to_char(myrec_seq.seqval,'FM000000');
RETURN lasttid;



END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION sia405_abwasser_2015_2_d.basket_update()
OWNER TO postgres;
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
-- neu 26.11.2016 Stefan Burckhardt / 4.7.2017 corrected / 9.10.2018
-- Updates data in vsa_dss_2015_2_d_3122.t_ili2db_import_basket with last tid from t_key_object

-- Function: vsa_dss_2015_2_d_3122.basket_update()

-- DROP FUNCTION vsa_dss_2015_2_d_3122.basket_update();

CREATE OR REPLACE FUNCTION vsa_dss_2015_2_d_3122.basket_update()
RETURNS integer AS
$BODY$
DECLARE
lasttid integer;
BEGIN
--get sequence for table
-- SELECT nextval('qgep.seq_' || table_name || '_oid') AS seqval INTO myrec_seq;
-- SELECT nextval('sia405_abwasser_2015_2_d_301.seq_' || table_name || '_tid') AS seqval INTO myrec_seq;

SELECT t_lastuniqueid INTO lasttid FROM vsa_dss_2015_2_d_3122.t_key_object;


-- 25.11.2016
RAISE NOTICE '[basket_update]: lasttid is %', lasttid; -- Print lasttid


-- adapt t_lastuniqueid in t_key_object
UPDATE vsa_dss_2015_2_d_3122.t_ili2db_import_basket
SET t_id = lasttid + 1
, end_t_id = lasttid
, objectcount = lasttid - 2
WHERE import = 2;

IF NOT FOUND THEN
RAISE EXCEPTION 'sequence for table basket_update not found - first data will be inserte';
INSERT INTO vsa_dss_2015_d_391.t_ili2db_import_basket (t_id, import, basket, objectcount, start_t_id, end_t_id) VALUES (lasttid + 1, 2, 3, lasttid - 2, 3, lasttid);

ELSE
RAISE NOTICE 't_ili2db_import_basket updated %', lasttid;
-- SELECT setval (sia405_abwasser_2015_2_d_340.t_ili2db_seq, lasttid + 1);
END IF;
-- RETURN myrec_prefix.prefix || myrec_shortcut.shortcut_en || to_char(myrec_seq.seqval,'FM000000');
-- RETURN myrec_prefix.prefix || to_char(myrec_seq.seqval,'FM000000');
RETURN lasttid;



END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION vsa_dss_2015_2_d_3122.basket_update()
OWNER TO postgres;
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
-- this file looks up the t_id for foreignkeys (OID) for the tables of the import/export schema with ili2pg.
-- questions regarding this function should be directed to Stefan Burckhardt stefan.burckhardt@sjib.ch
-- basis ist tid_lookup.sql
-- schema für export heisst sia405_abwasser_2015_2_d.
-- last update 18.11.2016 Stefan Burckhardt

-- function for looking up t_id
CREATE OR REPLACE FUNCTION sia405_abwasser_2015_2_d.tid_lookup(table_name text, obj_id_ref text)
-- RETURNS text AS
RETURNS integer AS
$BODY$
DECLARE
tid_ref integer;
-- newtid integer;
-- myrec_prefix record;
-- myrec_shortcut record;
-- myrec_seq record;
BEGIN
-- 9.3.2016 check whether obj_id_ref NOT IS NULL
IF obj_id_ref IS NULL THEN
tid_ref = NULL;
RAISE NOTICE '[tid_lookup]: obj_id is NULL . tid_ref set NULL also'; -- Print newtid
ELSE
-- get tid_ref for foreignkey
-- SELECT t_id INTO tid_ref FROM sia405_abwasser_2015_2_d.baseclass WHERE t_ili_tid = 'ch13p7mzOG000002';
SELECT t_id INTO tid_ref FROM sia405_abwasser_2015_2_d.baseclass WHERE t_ili_tid = obj_id_ref;

IF NOT FOUND THEN
-- 13.2.2016 / 9.3.2016 improved error message
-- RAISE EXCEPTION 'tid_ref for table % not found', table_name;
RAISE NOTICE '[tid_lookup]: Corresponding to obj_id % ->',obj_id_ref; -- Print newtid
RAISE NOTICE 'tid_ref for table % not found', table_name;
RAISE EXCEPTION 'Missing t_id in table baseclass';

ELSE
-- 12.1.2016
-- 13.2.2016 comment out to speed up
-- 9.3.2016 Hineis ergänzt mit OBJ_ID
RAISE NOTICE '[tid_lookup]: Corresponding to obj_id % ->',obj_id_ref; -- Print newtid
RAISE NOTICE 'tid_ref is %', tid_ref;

END IF;
END IF;

RETURN tid_ref;

END;
$BODY$
-- 12.1.2016 geändert LANGUAGE plpgsql STABLE
LANGUAGE plpgsql VOLATILE
COST 100;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- 24.11.2016 auch create statement nötig, Tabelle fehlt in --createscript (an Eisenhut gemeldet)
-- Stefan Burckhardt

-- Table: sia405_abwasser_2015_2_d.t_key_object

DROP TABLE IF EXISTS sia405_abwasser_2015_2_d.t_key_object;

CREATE TABLE sia405_abwasser_2015_2_d.t_key_object
(
t_key character varying(30) NOT NULL,
t_lastuniqueid integer NOT NULL,
t_lastchange timestamp without time zone NOT NULL,
t_createdate timestamp without time zone NOT NULL,
t_user character varying(40) NOT NULL,
CONSTRAINT t_key_object_pkey PRIMARY KEY (t_key)
)
WITH (
OIDS=FALSE
);
ALTER TABLE sia405_abwasser_2015_2_d.t_key_object
OWNER TO postgres;

-- erster Eintrag in t_key_object

INSERT INTO sia405_abwasser_2015_2_d.t_key_object (t_key, t_lastuniqueid, t_lastchange, t_createdate, t_user) VALUES ( 't_id', 0, current_timestamp, current_timestamp, 'postgres');
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- View: sia405_abwasser_2015_2_d.vw_sia405_baseclass_metaattribute

-- DROP VIEW IF EXISTS sia405_abwasser_2015_2_d.vw_sia405_baseclass_metaattribute;

CREATE OR REPLACE VIEW sia405_abwasser_2015_2_d.vw_sia405_baseclass_metaattribute AS
SELECT sia405_baseclass.t_id,
sia405_baseclass.obj_id,
metaattribute.datenherr,
metaattribute.datenlieferant,
metaattribute.letzte_aenderung
FROM sia405_abwasser_2015_2_d.sia405_baseclass
LEFT JOIN sia405_abwasser_2015_2_d.metaattribute ON sia405_baseclass.t_id = metaattribute.sia405_baseclass_metaattribute;

ALTER TABLE sia405_abwasser_2015_2_d.vw_sia405_baseclass_metaattribute
OWNER TO postgres;
Loading

0 comments on commit f667243

Please sign in to comment.