How do you examine objects from psql?
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
:
Show definitions of index columns in
\d index_name
(Khee Chin)The definition is useful for expression indexes.
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.:
=> SELECT oid FROM pg_catalog.pg_class c WHERE c.relname LIKE 'my_index';
oid
-------
25240
(1 row)
=> SELECT attname, attnum FROM pg_attribute a WHERE a.attrelid = '25240';
attname | attnum
------------------+--------
iso_country_code | 1
type_name | 2
pg_expression_3 | 3
(3 rows)
=> SELECT pg_get_indexdef(25240, 3, true);
pg_get_indexdef
-----------------
upper(name)
(1 row)
精彩评论