Create aggregates only if they do not exist
This commit is contained in:
parent
ac51256463
commit
4118b57f1f
@ -10,10 +10,22 @@ CREATE OR REPLACE FUNCTION
|
|||||||
END
|
END
|
||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
-- Create aggregate if it did not exist
|
||||||
CREATE AGGREGATE CDB_PyAgg(NUMERIC[])(
|
DO $$
|
||||||
|
BEGIN
|
||||||
|
IF NOT EXISTS (
|
||||||
|
SELECT *
|
||||||
|
FROM pg_catalog.pg_proc p
|
||||||
|
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
|
||||||
|
WHERE n.nspname = 'cdb_crankshaft'
|
||||||
|
AND p.proname = 'cdb_pyagg'
|
||||||
|
AND p.proisagg)
|
||||||
|
THEN
|
||||||
|
CREATE AGGREGATE CDB_PyAgg(NUMERIC[]) (
|
||||||
SFUNC = CDB_PyAggS,
|
SFUNC = CDB_PyAggS,
|
||||||
STYPE = Numeric[],
|
STYPE = Numeric[],
|
||||||
INITCOND = "{}"
|
INITCOND = "{}"
|
||||||
);
|
);
|
||||||
|
END IF;
|
||||||
|
END
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
@ -41,9 +41,23 @@ BEGIN
|
|||||||
END
|
END
|
||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
CREATE AGGREGATE CDB_WeightedMean(geometry(Point, 4326), NUMERIC)(
|
-- Create aggregate if it did not exist
|
||||||
|
DO $$
|
||||||
|
BEGIN
|
||||||
|
IF NOT EXISTS (
|
||||||
|
SELECT *
|
||||||
|
FROM pg_catalog.pg_proc p
|
||||||
|
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
|
||||||
|
WHERE n.nspname = 'cdb_crankshaft'
|
||||||
|
AND p.proname = 'cdb_weightedmean'
|
||||||
|
AND p.proisagg)
|
||||||
|
THEN
|
||||||
|
CREATE AGGREGATE CDB_WeightedMean(geometry(Point, 4326), NUMERIC) (
|
||||||
SFUNC = CDB_WeightedMeanS,
|
SFUNC = CDB_WeightedMeanS,
|
||||||
FINALFUNC = CDB_WeightedMeanF,
|
FINALFUNC = CDB_WeightedMeanF,
|
||||||
STYPE = Numeric[],
|
STYPE = Numeric[],
|
||||||
INITCOND = "{0.0,0.0,0.0}"
|
INITCOND = "{0.0,0.0,0.0}"
|
||||||
);
|
);
|
||||||
|
END IF;
|
||||||
|
END
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
Loading…
Reference in New Issue
Block a user