Thread: pg_event_trigger_ddl_commands fails with cache lookup failed

pg_event_trigger_ddl_commands fails with cache lookup failed

From
Sven Klemm
Date:
Hello,

when creating an event trigger for ddl_command_end that calls
pg_event_trigger_ddl_commands certain statements will cause the
trigger to fail with a cache lookup error. The error happens on 12.5
and 13.2 i didnt test any other versions.

trg=# ALTER TABLE t ALTER COLUMN f1 DROP IDENTITY, ALTER COLUMN f1 SET
DATA TYPE bigint;
ERROR:  XX000: cache lookup failed for relation 13476892
CONTEXT:  PL/pgSQL function ddl_end() line 5 at FOR over SELECT rows
LOCATION:  getRelationTypeDescription, objectaddress.c:4178

To reproduce:
CREATE OR REPLACE FUNCTION ddl_end()
  RETURNS event_trigger AS $$
DECLARE
  r RECORD;
BEGIN
  FOR r IN SELECT * FROM pg_event_trigger_ddl_commands()
  LOOP
    RAISE NOTICE 'ddl_end: % %', r.command_tag, r.object_type;
  END LOOP;
END;
$$ LANGUAGE plpgsql;

CREATE EVENT TRIGGER ddl_end ON ddl_command_end EXECUTE PROCEDURE ddl_end();

CREATE TABLE t(f1 int NOT NULL GENERATED ALWAYS AS IDENTITY);
ALTER TABLE t ALTER COLUMN f1 DROP IDENTITY, ALTER COLUMN f1 SET DATA
TYPE bigint;

-- 
Regards, Sven Klemm