Geometry Equality Operator Not Available on pg_restore WIthout Explicit Type Casts

334 views Asked by At

Postgres 12, Postgis 3

Two triggers are originally defined w/ the criteria WHEN (OLD.geom IS DISTINCT FROM NEW.geom). The geom column is of type geometry.

This caused issues when pg_restore-ing the database due to the geometry operator for equals not being available:

pg_restore: while PROCESSING TOC:
pg_restore: from TOC entry 10233; 2620 673186 TRIGGER lines the_trigger_name geo
pg_restore: error: could not execute query: ERROR:  operator is not unique: public.geometry = public.geometry
LINE 1: ...public.lines FOR EACH ROW WHEN ((old.geom IS DISTINC...
                                                             ^
HINT:  Could not choose a best candidate operator. You might need to add explicit type casts.
Command was: CREATE TRIGGER the_trigger_name AFTER UPDATE ON public.lines FOR EACH ROW WHEN ((old.geom IS DISTINCT FROM new.geom)) EXECUTE FUNCTION public.the_function_name();

The backup database uses postgis 3.0.0

We load it in two different ways:

  • in one environment (postgis 3.0.1), we use a a database dump in the plain text (default) format (pg_dump -F p), and load it up by just executing the plaintext file, like psql -f /my/file.sql
    • this reported the error, but the database load still works
  • in another environment (postgis 3.0.2), we use a a database dump in the custom format (pg_dump -F custom) and load it up by running pg_restore --single-transaction < “$DB_FILE”
    • this reported the error, and failed

Adding a ::geometry cast on OLD/NEW geom fixes this issue. Why is pg unable to determine the equality operator in certain contexts (without type casts)?

0

There are 0 answers