set client_min_messages = warning;
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)::numeric(10,2);
 manhattan_dist 
----------------
           8.00
(1 row)

select euclidean_dist(1, 1, 5, 5)::numeric(10,2);
 euclidean_dist 
----------------
           5.66
(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;
