I want to examine an index (and other objects) from psql.
I created the index with:
CREATE INDEX my_index on "my_table" (iso_country_code, type_name, UPPER(name) varchar_pattern_ops);
In psql I used the describe command:
db=> \d+ my_index
Index "public.my_index"
Column | Type | Storage | Description
------------------+------------------------+----------+-------------
iso_country_code | character varying(3) | extended |
type_name | character varying(300) | extended |
pg_expression_3 | text | extended |
btree, for table "public.my_table"
The expression in the last field of the index says only pg_expression_3. Why does the expression not show up in the psql output?
I can retrieve the table schema including the CREATE INDEX statements using pg_dump:
pg_dump --table my_table --schema-only my_db
It’s clearly pre-9.0 behaviour, take a look into
E.5. Release 9.0:For previous versions you can still fetch expression manually traversing system catalogs and using
pg_get_indexdef(index_oid, column_no, pretty_bool)function, e.g.: