diff --git a/CHANGELOG.md b/CHANGELOG.md
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,6 @@
+# hpqtypes-1.9.2.1 (2021-11-04)
+* Improve an SQL query that gets information about composite types.
+
 # hpqtypes-1.9.2.0 (2021-09-29)
 * Add method withFrozenLastQuery to (temporarily) stop recording queries.
 
diff --git a/hpqtypes.cabal b/hpqtypes.cabal
--- a/hpqtypes.cabal
+++ b/hpqtypes.cabal
@@ -1,5 +1,5 @@
 name:                hpqtypes
-version:             1.9.2.0
+version:             1.9.2.1
 synopsis:            Haskell bindings to libpqtypes
 
 description:         Efficient and easy-to-use bindings to (slightly modified)
@@ -126,7 +126,7 @@
 
   build-depends:       base              >= 4.9     && < 5
                      , text              >= 0.11
-                     , aeson             >= 1.0
+                     , aeson             >= 1.0     && < 2.0
                      , async             >= 2.1.1.1
                      , bytestring        >= 0.9
                      , semigroups        >= 0.16
diff --git a/libpqtypes/src/handler.c b/libpqtypes/src/handler.c
--- a/libpqtypes/src/handler.c
+++ b/libpqtypes/src/handler.c
@@ -939,30 +939,16 @@
 "(" \
 "  SELECT * FROM information_schema._pg_expandarray(%text[])" \
 ")," \
-"curpath AS" \
-"(" \
-"  SELECT * FROM information_schema._pg_expandarray(current_schemas(true))" \
-")," \
 "composites AS" \
 "(" \
-"  SELECT n.n AS idx, n.x AS nspname, t.x AS typname" \
-"    FROM nspnames n LEFT JOIN typnames t ON n.n = t.n" \
-"      AND n.x IS NOT NULL" \
-"      WHERE t.x IS NOT NULL" \
-"  UNION ALL" \
-"  SELECT n.n AS idx," \
-"  (" \
-"    SELECT n.nspname from pg_type nt JOIN pg_namespace n ON " \
-         "nt.typnamespace = n.oid" \
-"      JOIN curpath c ON c.x = n.nspname" \
-"      WHERE nt.typname = t.x" \
-"      ORDER BY c.n LIMIT 1" \
-"  ) AS nspname, t.x AS typname" \
-"    FROM nspnames n LEFT JOIN typnames t ON n.n = t.n" \
-"      AND n.x IS NULL" \
-"      WHERE t.x IS NOT NULL" \
+  "SELECT t.n as idx, " \
+"          to_regtype(CASE WHEN n.x IS NULL" \
+"                     THEN quote_ident(t.x)" \
+"                     ELSE quote_ident(n.x) || '.' || quote_ident(t.x)" \
+"                     END) AS typoid" \
+"  FROM nspnames n JOIN typnames t USING (n)" \
 ")" \
-"SELECT idx, t.oid AS typoid, a.oid AS arroid, t.typlen," \
+"SELECT c.idx, t.oid AS typoid, a.oid AS arroid, t.typlen," \
 " (" \
 "   CASE WHEN %bool THEN (" \
 "   SELECT array_to_string" \
@@ -983,8 +969,8 @@
 "    ), ' ')" \
 "  ) ELSE NULL END) AS arr_props" \
 "  FROM composites c" \
-"  JOIN pg_type t ON t.typname = c.typname" \
-"  JOIN pg_namespace n ON t.typnamespace = n.oid AND n.nspname = c.nspname" \
+"  JOIN pg_type t ON t.oid = c.typoid" \
+"  JOIN pg_namespace n ON t.typnamespace = n.oid" \
 "  JOIN pg_type a ON a.oid = t.typarray" \
 "  ORDER BY idx;"
 
