Find out the indexed columns

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi All,
I have a condition based index created. I see that the postgres metadata table doesn't return columns associated with condition based indexes.

Example:
ssdb=# SELECT indexdef FROM pg_indexes WHERE indexname = 'test_u01';
                             indexdef
------------------------------------------------------------------
 CREATE UNIQUE INDEX test_idx1 ON test USING btree ((+
 CASE inet_type                                               +
     WHEN 2 THEN a                           +
     WHEN 4 THEN a                           +
     ELSE NULL::character varying                                +
 END), (                                                         +
 CASE inet_type                                               +
     WHEN 2 THEN ipaddress                                      +
     WHEN 4 THEN ipaddress                                      +
     ELSE NULL::character varying                                +
 END), (                                                         +
 CASE inet_type                                               +
     WHEN 2 THEN port                                         +
     WHEN 4 THEN port                                         +
     ELSE NULL::bigint                                           +
 END))
(1 row)

The below query is unable to find the indexed columns (a,ipadress,port) through the metadata tables for the above _expression_ based index. 

SELECT ix.indisprimary as contype,pg_get_userbyid(t.relowner) as table_owner, t.relname as table_name, pg_get_userbyid(i.relowner) as index_owner, i.relname as index_name, a.attname as att_name, pg_catalog.format_type(a.atttypid, a.atttypmod) AS data_type FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND a.attnum = ANY(ix.indkey) AND i.relname = 'test_idx1';

How do I find out the associated columns for such an index?

Regards,
nik

[Index of Archives]     [Postgresql Home]     [Postgresql General]     [Postgresql Performance]     [Postgresql PHP]     [Postgresql Jobs]     [PHP Users]     [PHP Databases]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Yosemite Forum]

  Powered by Linux