We don't need to fix this though (i.e., make the query continue to somehow work), we need to detect the situation and return some kind of error as opposed to crashing the server. The transaction itself is doing something illegal and can be forced to abort. Alternatively, maybe the ALTER TYPE command can emit the error that it is unable to alter the type as it is already in use by the current session. But that would close off possible non-problematic uses of ALTER TYPE in this situation
Yeah, that makes sense. If we create a table using type foo, the alter operation would error out like that.
create table t (a foo);
alter type foo alter attribute b type text; ERROR: cannot alter type "foo" because column "t.a" uses it
Maybe we can likewise record the dependencies for the type if it's being used in other more scenarios besides as a column in some table?