diff --git a/nix/tests/expected/pg_tle.out b/nix/tests/expected/pg_tle.out new file mode 100644 index 000000000..cffce1d67 --- /dev/null +++ b/nix/tests/expected/pg_tle.out @@ -0,0 +1,91 @@ +select + pgtle.install_extension( + 'pg_distance', + '0.1', + 'Distance functions for two points', + $_pg_tle_$ + CREATE FUNCTION dist(x1 float8, y1 float8, x2 float8, y2 float8, norm int) + RETURNS float8 + AS $$ + SELECT (abs(x2 - x1) ^ norm + abs(y2 - y1) ^ norm) ^ (1::float8 / norm); + $$ LANGUAGE SQL; + + CREATE FUNCTION manhattan_dist(x1 float8, y1 float8, x2 float8, y2 float8) + RETURNS float8 + AS $$ + SELECT dist(x1, y1, x2, y2, 1); + $$ LANGUAGE SQL; + + CREATE FUNCTION euclidean_dist(x1 float8, y1 float8, x2 float8, y2 float8) + RETURNS float8 + AS $$ + SELECT dist(x1, y1, x2, y2, 2); + $$ LANGUAGE SQL; + $_pg_tle_$ + ); + install_extension +------------------- + t +(1 row) + +create extension pg_distance; +select manhattan_dist(1, 1, 5, 5); + manhattan_dist +---------------- + 8 +(1 row) + +select euclidean_dist(1, 1, 5, 5); + euclidean_dist +------------------- + 5.656854249492381 +(1 row) + +SELECT pgtle.install_update_path( + 'pg_distance', + '0.1', + '0.2', + $_pg_tle_$ + CREATE OR REPLACE FUNCTION dist(x1 float8, y1 float8, x2 float8, y2 float8, norm int) + RETURNS float8 + AS $$ + SELECT (abs(x2 - x1) ^ norm + abs(y2 - y1) ^ norm) ^ (1::float8 / norm); + $$ LANGUAGE SQL IMMUTABLE PARALLEL SAFE; + + CREATE OR REPLACE FUNCTION manhattan_dist(x1 float8, y1 float8, x2 float8, y2 float8) + RETURNS float8 + AS $$ + SELECT dist(x1, y1, x2, y2, 1); + $$ LANGUAGE SQL IMMUTABLE PARALLEL SAFE; + + CREATE OR REPLACE FUNCTION euclidean_dist(x1 float8, y1 float8, x2 float8, y2 float8) + RETURNS float8 + AS $$ + SELECT dist(x1, y1, x2, y2, 2); + $$ LANGUAGE SQL IMMUTABLE PARALLEL SAFE; + $_pg_tle_$ + ); + install_update_path +--------------------- + t +(1 row) + +select + pgtle.set_default_version('pg_distance', '0.2'); + set_default_version +--------------------- + t +(1 row) + +alter extension pg_distance update; +drop extension pg_distance; +select + pgtle.uninstall_extension('pg_distance'); + uninstall_extension +--------------------- + t +(1 row) + +-- Restore original state if any of the above fails +drop extension pg_tle cascade; +create extension pg_tle; diff --git a/nix/tests/sql/pg_tle.sql b/nix/tests/sql/pg_tle.sql new file mode 100644 index 000000000..3af128026 --- /dev/null +++ b/nix/tests/sql/pg_tle.sql @@ -0,0 +1,70 @@ +select + pgtle.install_extension( + 'pg_distance', + '0.1', + 'Distance functions for two points', + $_pg_tle_$ + CREATE FUNCTION dist(x1 float8, y1 float8, x2 float8, y2 float8, norm int) + RETURNS float8 + AS $$ + SELECT (abs(x2 - x1) ^ norm + abs(y2 - y1) ^ norm) ^ (1::float8 / norm); + $$ LANGUAGE SQL; + + CREATE FUNCTION manhattan_dist(x1 float8, y1 float8, x2 float8, y2 float8) + RETURNS float8 + AS $$ + SELECT dist(x1, y1, x2, y2, 1); + $$ LANGUAGE SQL; + + CREATE FUNCTION euclidean_dist(x1 float8, y1 float8, x2 float8, y2 float8) + RETURNS float8 + AS $$ + SELECT dist(x1, y1, x2, y2, 2); + $$ LANGUAGE SQL; + $_pg_tle_$ + ); + +create extension pg_distance; + +select manhattan_dist(1, 1, 5, 5); +select euclidean_dist(1, 1, 5, 5); + +SELECT pgtle.install_update_path( + 'pg_distance', + '0.1', + '0.2', + $_pg_tle_$ + CREATE OR REPLACE FUNCTION dist(x1 float8, y1 float8, x2 float8, y2 float8, norm int) + RETURNS float8 + AS $$ + SELECT (abs(x2 - x1) ^ norm + abs(y2 - y1) ^ norm) ^ (1::float8 / norm); + $$ LANGUAGE SQL IMMUTABLE PARALLEL SAFE; + + CREATE OR REPLACE FUNCTION manhattan_dist(x1 float8, y1 float8, x2 float8, y2 float8) + RETURNS float8 + AS $$ + SELECT dist(x1, y1, x2, y2, 1); + $$ LANGUAGE SQL IMMUTABLE PARALLEL SAFE; + + CREATE OR REPLACE FUNCTION euclidean_dist(x1 float8, y1 float8, x2 float8, y2 float8) + RETURNS float8 + AS $$ + SELECT dist(x1, y1, x2, y2, 2); + $$ LANGUAGE SQL IMMUTABLE PARALLEL SAFE; + $_pg_tle_$ + ); + + +select + pgtle.set_default_version('pg_distance', '0.2'); + +alter extension pg_distance update; + +drop extension pg_distance; + +select + pgtle.uninstall_extension('pg_distance'); + +-- Restore original state if any of the above fails +drop extension pg_tle cascade; +create extension pg_tle;