refactor(db): consider IF EXIST condition in SQL scripts

This commit is contained in:
dancingCycle 2023-06-16 10:22:12 +02:00
parent 03fca0d536
commit 38b3e43173
6 changed files with 9 additions and 9 deletions

View File

@ -102,4 +102,4 @@ SELECT foo.id,
WHERE (lk.name = ANY (ARRAY['Braunschweig','Salzgitter','Wolfsburg','Gifhorn','Landkreis Goslar','Landkreis Helmstedt','Landkreis Peine','Landkreis Wolfenbüttel'])) AND foo.name IS NOT NULL AND foo.kategorie <> 999
ORDER BY lk.name, gem.name, foo.kategorie, foo.name;
CREATE TABLE :schema.tbl_bus_stop AS SELECT * FROM :schema.vw_bus_stop;
CREATE TABLE IF NOT EXISTS :schema.tbl_bus_stop AS SELECT * FROM :schema.vw_bus_stop;

View File

@ -5,7 +5,7 @@ SET search_path to :schema, public;
DROP TABLE IF EXISTS :schema.tbl_poi;
DROP VIEW IF EXISTS :schema.vw_poi;
CREATE OR REPLACE VIEW :schema.vw_poi AS
CREATE OR REPLACE VIEW IF NOT EXISTS :schema.vw_poi AS
SELECT foo.id, foo.osm_id, foo.name, foo.kategorie, lk.name as landkreis,
CASE WHEN gem.name IS NULL THEN lk.name ELSE gem.name END as gemeinde,
@ -271,4 +271,4 @@ LEFT JOIN vw_municipalities gem ON st_contains(gem.way, st_transform(st_geomfrom
WHERE (lk.name = ANY (ARRAY['Braunschweig','Salzgitter','Wolfsburg','Gifhorn','Landkreis Goslar','Landkreis Helmstedt','Landkreis Peine','Landkreis Wolfenbüttel'])) AND foo.name IS NOT NULL AND foo.kategorie <> 999
ORDER BY lk.name, gem.name, foo.kategorie, foo.name;
CREATE TABLE :schema.tbl_poi AS SELECT * FROM :schema.vw_poi;
CREATE TABLE IF NOT EXISTS :schema.tbl_poi AS SELECT * FROM :schema.vw_poi;

View File

@ -5,7 +5,7 @@ SET search_path to :schema, public;
DROP TABLE IF EXISTS :schema.tbl_railway;
DROP VIEW IF EXISTS :schema.vw_railway;
CREATE OR REPLACE VIEW :schema.vw_railway AS
CREATE OR REPLACE VIEW IF NOT EXISTS :schema.vw_railway AS
SELECT foo.id,
foo.osm_id,
foo.railway,
@ -88,4 +88,4 @@ SELECT foo.id,
WHERE (lk.name = ANY (ARRAY['Braunschweig','Salzgitter','Wolfsburg','Gifhorn','Landkreis Goslar','Landkreis Helmstedt','Landkreis Peine','Landkreis Wolfenbüttel'])) AND foo.name IS NOT NULL
ORDER BY lk.name, gem.name, foo.name;
CREATE TABLE :schema.tbl_railway AS SELECT * FROM :schema.vw_railway;
CREATE TABLE IF NOT EXISTS :schema.tbl_railway AS SELECT * FROM :schema.vw_railway;

View File

@ -2,9 +2,9 @@
CREATE SCHEMA IF NOT EXISTS :schema;
SET search_path to :schema, public;
DROP VIEW :schema.vw_counties CASCADE;
DROP VIEW IF EXISTS :schema.vw_counties CASCADE;
CREATE OR REPLACE VIEW :schema.vw_counties AS
CREATE OR REPLACE VIEW IF NOT EXISTS :schema.vw_counties AS
SELECT planet_osm_polygon.osm_id,
planet_osm_polygon.name,
planet_osm_polygon.boundary,

View File

@ -2,7 +2,7 @@
CREATE SCHEMA IF NOT EXISTS :schema;
SET search_path to :schema, public;
CREATE OR REPLACE VIEW :schema.vw_export_poi AS
CREATE OR REPLACE VIEW IF NOT EXISTS :schema.vw_export_poi AS
SELECT foo.id, foo.kat, tl.deutsch as kat_de, tl.english as kat_en, foo.kat_sub as kat_sub_de, foo.kat_sub as kat_sub_en, foo.name,
foo.adr_street AS strasse, foo.plz, foo.gemeinde, foo.landkreis,

View File

@ -2,7 +2,7 @@
CREATE SCHEMA IF NOT EXISTS :schema;
SET search_path to :schema, public;
DROP VIEW :schema.vw_municipalities CASCADE;
DROP VIEW IF EXISTS :schema.vw_municipalities CASCADE;
CREATE OR REPLACE VIEW :schema.vw_municipalities AS
SELECT planet_osm_polygon.osm_id,