A type confusion vulnerability in PostgreSQL's min/max aggregate optimization allows an attacker who can create objects to execute arbitrary code with the privileges of the database operating system user. This occurs when a user-defined aggregate uses a SORTOP option that causes the planner to treat the aggregate's input and result as the same type, even when they differ. Versions prior to PostgreSQL 14.25, 15.20, 16.16, 17.12, and 18.7 are affected.