I have a table with a cube column, but restoring the database from pg_dump stopped working from postgres 15.6 (also a problem on postgres 16.3). The error I get is on the function ll_to_earth in theearthdistance extension.
pg_dump always set the searchpath to empty:
SELECT pg_catalog.set_config('search_path', '', false);
Setting search_path doesn't solve the problem: https://stackoverflow.com/a/63591713
. There is no way to set search_path on a table, but even setting on a function is not preserved by pg_dump:
ALTER FUNCTION public.ll_to_earth SET search_path = public;
Script to reproduce the issue:
set -x
psql postgresql://postgres@localhost:5432 -c "CREATE DATABASE earth_test"
psql postgresql://postgres@localhost:5432/earth_test <<EOF
CREATE EXTENSION IF NOT EXISTS cube WITH SCHEMA public;
CREATE EXTENSION IF NOT EXISTS earthdistance WITH SCHEMA public;
CREATE TABLE town (
name varchar,
lon float,
lat float,
location public.cube GENERATED ALWAYS AS (public.earth_box(public.ll_to_earth(lat, lon), 0)) STORED
);
EOF
pg_dump postgresql://postgres@localhost:5432/earth_test > earth_test.sql
psql postgresql://postgres@localhost:5432 -c "CREATE DATABASE earth_test2";
psql postgresql://postgres@localhost:5432/earth_test2 -f earth_test.sql
Output:
+ psql postgresql://postgres@localhost:5432 -c 'CREATE DATABASE earth_test'
CREATE DATABASE
+ psql postgresql://postgres@localhost:5432/earth_test
CREATE EXTENSION
CREATE EXTENSION
CREATE TABLE
+ pg_dump postgresql://postgres@localhost:5432/earth_test
+ psql postgresql://postgres@localhost:5432 -c 'CREATE DATABASE earth_test2'
CREATE DATABASE
+ psql postgresql://postgres@localhost:5432/earth_test2 -f earth_test.sql
SET
SET
SET
SET
SET
set_config
------------
(1 row)
SET
SET
SET
SET
ALTER SCHEMA
CREATE EXTENSION
COMMENT
CREATE EXTENSION
COMMENT
SET
SET
psql:earth_test.sql:69: ERROR: type "earth" does not exist
LINE 1: ...ians($1))*sin(radians($2))),earth()*sin(radians($1)))::earth
^
QUERY: SELECT cube(cube(cube(earth()*cos(radians($1))*cos(radians($2))),earth()*cos(radians($1))*sin(radians($2))),earth()*sin(radians($1)))::earth
CONTEXT: SQL function "ll_to_earth" during inlining