exec-ddl
CREATE TABLE pg_attribute (
    attrelid oid NOT NULL,
    attname text NOT NULL,
    atttypid oid NOT NULL,
    attstattarget bigint NOT NULL,
    attlen bigint NOT NULL,
    attnum bigint NOT NULL,
    attndims bigint NOT NULL,
    attcacheoff bigint NOT NULL,
    atttypmod bigint NOT NULL,
    attbyval boolean NOT NULL,
    attstorage text NOT NULL,
    attalign text NOT NULL,
    attnotnull boolean NOT NULL,
    atthasdef boolean NOT NULL,
    attidentity text NOT NULL,
    attgenerated text NOT NULL,
    attisdropped boolean NOT NULL,
    attislocal boolean NOT NULL,
    attinhcount bigint NOT NULL,
    attcollation oid NOT NULL,
    attacl text[],
    attoptions text[],
    attfdwoptions text[],
    PRIMARY KEY (attrelid, attnum),
    UNIQUE INDEX pg_attribute_relid_attnam_index (attrelid, attname)
);
----

exec-ddl
CREATE TABLE pg_attrdef (
    oid oid PRIMARY KEY,
    adrelid oid NOT NULL,
    adnum bigint NOT NULL,
    adbin text,
    adsrc text,
    UNIQUE INDEX pg_attrdef_adrelid_adnum_index (adrelid, adnum)
);
----

exec-ddl
CREATE TABLE pg_collation (
    oid oid PRIMARY KEY,
    collname text NOT NULL,
    collnamespace oid NOT NULL,
    collowner oid NOT NULL,
    collencoding bigint NOT NULL,
    collcollate text NOT NULL,
    collctype text NOT NULL,
    UNIQUE INDEX pg_collation_name_enc_nsp_index (collname, collencoding, collnamespace)
);
----

exec-ddl
CREATE TABLE pg_type (
    oid oid PRIMARY KEY,
    typname text NOT NULL,
    typnamespace oid NOT NULL,
    typowner oid NOT NULL,
    typlen bigint NOT NULL,
    typbyval boolean NOT NULL,
    typtype text NOT NULL,
    typcategory text NOT NULL,
    typispreferred boolean NOT NULL,
    typisdefined boolean NOT NULL,
    typdelim text NOT NULL,
    typrelid oid NOT NULL,
    typelem oid NOT NULL,
    typarray oid NOT NULL,
    typinput oid NOT NULL,
    typoutput oid NOT NULL,
    typreceive oid NOT NULL,
    typsend oid NOT NULL,
    typmodin oid NOT NULL,
    typmodout oid NOT NULL,
    typanalyze oid NOT NULL,
    typalign text NOT NULL,
    typstorage text NOT NULL,
    typnotnull boolean NOT NULL,
    typbasetype oid NOT NULL,
    typtypmod bigint NOT NULL,
    typndims bigint NOT NULL,
    typcollation oid NOT NULL,
    typdefaultbin text,
    typdefault text,
    typacl text[],
    UNIQUE INDEX pg_type_typname_nsp_index (typname, typnamespace)
);
----

exec-ddl
CREATE TABLE numbers (
  id INT PRIMARY KEY
);
----

opt
SELECT a.attname,
  format_type(a.atttypid, a.atttypmod),
  pg_get_expr(d.adbin, d.adrelid),
  a.attnotnull,
  a.atttypid,
  a.atttypmod,
  (SELECT c.collname
   FROM pg_collation c, pg_type t
   WHERE c.oid = a.attcollation
   AND t.oid = a.atttypid
   AND a.attcollation <> t.typcollation),
   col_description(a.attrelid, a.attnum) AS comment
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"numbers"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
----
sort
 ├── columns: attname:2!null format_type:75 pg_get_expr:76 attnotnull:13!null atttypid:3!null atttypmod:9!null collname:77 comment:85  [hidden: attnum:6!null]
 ├── stable
 ├── key: (6)
 ├── fd: (6)-->(2,3,9,13,75-77,85), (2)-->(3,6,9,13,75-77,85), (3,9)-->(75)
 ├── ordering: +6
 └── project
      ├── columns: format_type:75 pg_get_expr:76 collname:77 comment:85 attname:2!null atttypid:3!null attnum:6!null atttypmod:9!null attnotnull:13!null
      ├── stable
      ├── key: (6)
      ├── fd: (6)-->(2,3,9,13,75-77,85), (2)-->(3,6,9,13,75-77,85), (3,9)-->(75)
      ├── distinct-on
      │    ├── columns: attname:2!null atttypid:3!null attnum:6!null atttypmod:9!null attnotnull:13!null adrelid:27 adbin:29 c.collname:34 c.comment:84
      │    ├── grouping columns: attnum:6!null
      │    ├── immutable
      │    ├── key: (6)
      │    ├── fd: (6)-->(2,3,9,13,27,29,34,84), (2)-->(3,6,9,13,27,29,34)
      │    ├── right-join (hash)
      │    │    ├── columns: attrelid:1!null attname:2!null atttypid:3!null attnum:6!null atttypmod:9!null attnotnull:13!null adrelid:27 adbin:29 c.collname:34 type:81 object_id:82 sub_id:83 c.comment:84 column86:86!null
      │    │    ├── immutable
      │    │    ├── fd: ()-->(1,86), (6)-->(2,3,9,13,27,29,34), (2)-->(3,6,9,13,27,29,34)
      │    │    ├── select
      │    │    │    ├── columns: type:81!null object_id:82!null sub_id:83!null c.comment:84!null
      │    │    │    ├── fd: ()-->(81)
      │    │    │    ├── scan comments [as=c]
      │    │    │    │    └── columns: type:81!null object_id:82!null sub_id:83!null c.comment:84!null
      │    │    │    └── filters
      │    │    │         ├── type:81 = 2 [outer=(81), constraints=(/81: [/2 - /2]; tight), fd=()-->(81)]
      │    │    │         └── sub_id:83 != 0 [outer=(83), constraints=(/83: (/NULL - /-1] [/1 - ]; tight)]
      │    │    ├── project
      │    │    │    ├── columns: column86:86!null attrelid:1!null attname:2!null atttypid:3!null attnum:6!null atttypmod:9!null attnotnull:13!null adrelid:27 adbin:29 c.collname:34
      │    │    │    ├── immutable
      │    │    │    ├── key: (6)
      │    │    │    ├── fd: ()-->(1,86), (6)-->(2,3,9,13,27,29,34), (2)-->(3,6,9,13,27,29,34)
      │    │    │    ├── right-join (hash)
      │    │    │    │    ├── columns: attrelid:1!null attname:2!null atttypid:3!null attnum:6!null atttypmod:9!null attnotnull:13!null attisdropped:17!null attcollation:20!null adrelid:27 adnum:28 adbin:29 c.oid:33 c.collname:34 t.oid:42 typcollation:69
      │    │    │    │    ├── key: (6)
      │    │    │    │    ├── fd: ()-->(1,17), (6)-->(2,3,9,13,20,27-29,33,34,42,69), (2)-->(3,6,9,13,20), (28)-->(29), (33)-->(34), (42)-->(69)
      │    │    │    │    ├── inner-join (cross)
      │    │    │    │    │    ├── columns: c.oid:33!null c.collname:34!null t.oid:42!null typcollation:69!null
      │    │    │    │    │    ├── key: (33,42)
      │    │    │    │    │    ├── fd: (33)-->(34), (42)-->(69)
      │    │    │    │    │    ├── scan pg_collation@pg_collation_name_enc_nsp_index [as=c]
      │    │    │    │    │    │    ├── columns: c.oid:33!null c.collname:34!null
      │    │    │    │    │    │    ├── key: (33)
      │    │    │    │    │    │    └── fd: (33)-->(34)
      │    │    │    │    │    ├── scan pg_type [as=t]
      │    │    │    │    │    │    ├── columns: t.oid:42!null typcollation:69!null
      │    │    │    │    │    │    ├── key: (42)
      │    │    │    │    │    │    └── fd: (42)-->(69)
      │    │    │    │    │    └── filters
      │    │    │    │    │         └── c.oid:33 != typcollation:69 [outer=(33,69), constraints=(/33: (/NULL - ]; /69: (/NULL - ])]
      │    │    │    │    ├── left-join (lookup pg_attrdef [as=d])
      │    │    │    │    │    ├── columns: attrelid:1!null attname:2!null atttypid:3!null attnum:6!null atttypmod:9!null attnotnull:13!null attisdropped:17!null attcollation:20!null adrelid:27 adnum:28 adbin:29
      │    │    │    │    │    ├── key columns: [26] = [26]
      │    │    │    │    │    ├── lookup columns are key
      │    │    │    │    │    ├── key: (6)
      │    │    │    │    │    ├── fd: ()-->(1,17), (6)-->(2,3,9,13,20,27-29), (2)-->(3,6,9,13,20), (28)-->(29)
      │    │    │    │    │    ├── left-join (lookup pg_attrdef@pg_attrdef_adrelid_adnum_index [as=d])
      │    │    │    │    │    │    ├── columns: attrelid:1!null attname:2!null atttypid:3!null attnum:6!null atttypmod:9!null attnotnull:13!null attisdropped:17!null attcollation:20!null d.oid:26 adrelid:27 adnum:28
      │    │    │    │    │    │    ├── key columns: [1 6] = [27 28]
      │    │    │    │    │    │    ├── lookup columns are key
      │    │    │    │    │    │    ├── key: (6)
      │    │    │    │    │    │    ├── fd: ()-->(1,17), (6)-->(2,3,9,13,20,26-28), (2)-->(3,6,9,13,20), (26)-->(27,28), (27,28)-->(26)
      │    │    │    │    │    │    ├── select
      │    │    │    │    │    │    │    ├── columns: attrelid:1!null attname:2!null atttypid:3!null attnum:6!null atttypmod:9!null attnotnull:13!null attisdropped:17!null attcollation:20!null
      │    │    │    │    │    │    │    ├── key: (6)
      │    │    │    │    │    │    │    ├── fd: ()-->(1,17), (6)-->(2,3,9,13,20), (2)-->(3,6,9,13,20)
      │    │    │    │    │    │    │    ├── scan pg_attribute [as=a]
      │    │    │    │    │    │    │    │    ├── columns: attrelid:1!null attname:2!null atttypid:3!null attnum:6!null atttypmod:9!null attnotnull:13!null attisdropped:17!null attcollation:20!null
      │    │    │    │    │    │    │    │    ├── constraint: /1/6: [/numbers/1 - /numbers]
      │    │    │    │    │    │    │    │    ├── key: (6)
      │    │    │    │    │    │    │    │    └── fd: ()-->(1), (6)-->(2,3,9,13,17,20), (2)-->(3,6,9,13,17,20)
      │    │    │    │    │    │    │    └── filters
      │    │    │    │    │    │    │         └── NOT attisdropped:17 [outer=(17), constraints=(/17: [/false - /false]; tight), fd=()-->(17)]
      │    │    │    │    │    │    └── filters
      │    │    │    │    │    │         ├── adrelid:27 = numbers [outer=(27), constraints=(/27: [/numbers - /numbers]; tight), fd=()-->(27)]
      │    │    │    │    │    │         └── adnum:28 > 0 [outer=(28), constraints=(/28: [/1 - ]; tight)]
      │    │    │    │    │    └── filters (true)
      │    │    │    │    └── filters
      │    │    │    │         ├── c.oid:33 = attcollation:20 [outer=(20,33), constraints=(/20: (/NULL - ]; /33: (/NULL - ]), fd=(20)==(33), (33)==(20)]
      │    │    │    │         └── t.oid:42 = atttypid:3 [outer=(3,42), constraints=(/3: (/NULL - ]; /42: (/NULL - ]), fd=(3)==(42), (42)==(3)]
      │    │    │    └── projections
      │    │    │         └── attrelid:1::INT8 [as=column86:86, outer=(1), immutable]
      │    │    └── filters
      │    │         ├── column86:86 = object_id:82 [outer=(82,86), constraints=(/82: (/NULL - ]; /86: (/NULL - ]), fd=(82)==(86), (86)==(82)]
      │    │         ├── sub_id:83 = attnum:6 [outer=(6,83), constraints=(/6: (/NULL - ]; /83: (/NULL - ]), fd=(6)==(83), (83)==(6)]
      │    │         └── attrelid:1 < 4294966962 [outer=(1), constraints=(/1: (/NULL - /4294966961]; tight)]
      │    └── aggregations
      │         ├── const-agg [as=attname:2, outer=(2)]
      │         │    └── attname:2
      │         ├── const-agg [as=atttypid:3, outer=(3)]
      │         │    └── atttypid:3
      │         ├── const-agg [as=atttypmod:9, outer=(9)]
      │         │    └── atttypmod:9
      │         ├── const-agg [as=attnotnull:13, outer=(13)]
      │         │    └── attnotnull:13
      │         ├── const-agg [as=adrelid:27, outer=(27)]
      │         │    └── adrelid:27
      │         ├── const-agg [as=adbin:29, outer=(29)]
      │         │    └── adbin:29
      │         ├── const-agg [as=c.collname:34, outer=(34)]
      │         │    └── c.collname:34
      │         └── first-agg [as=c.comment:84, outer=(84)]
      │              └── c.comment:84
      └── projections
           ├── format_type(atttypid:3, atttypmod:9) [as=format_type:75, outer=(3,9), stable]
           ├── pg_get_expr(adbin:29, adrelid:27) [as=pg_get_expr:76, outer=(27,29), stable]
           ├── c.collname:34 [as=collname:77, outer=(34)]
           └── c.comment:84 [as=comment:85, outer=(84)]
