sb::get_indexes (public)
sb::get_indexes table_name [ html_anchors_p ] [ pki ]
Defined in packages/schema-browser/tcl/schema-browser-procs-postgresql.tcl
Create statements for indexes on table_name.
- Parameters:
- table_name (required)
- html_anchors_p (optional, defaults to
"f"
)- pki (optional)
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
Source code: set return_string "\n" set prev_index "" set indexes [db_list_of_lists sb_get_indexes_select_1 { select relname as index_name, case when indisunique then ' UNIQUE' else NULL end as uniqueness, amname as index_type, indkey from pg_index i join (select oid from pg_class where relname = lower(:table_name)) c on (i.indrelid = c.oid) join pg_class index_class on (index_class.oid = i.indexrelid and not i.indisprimary) join pg_am a on (index_class.relam = a.oid) order by index_name}] if {$pki ne ""} { lappend indexes [list {PRIMARY KEY} { UNIQUE} {} $pki] } foreach index $indexes { lassign $index index_name uniqueness index_type indkey set index_clause "([join [split $indkey " "] ","])" append return_string "\nCREATE$uniqueness INDEX [string tolower $index_name] ON [string tolower $table_name] (" set sep "" # JCD: need to preserve the order of the index columns # since it matters a lot. db_foreach sb_get_indexes_select_2 " select a.attname as column_name, a.attnum from (select oid from pg_class where relname = lower(:table_name)) c join pg_attribute a on (c.oid = a.attrelid) where a.attnum in $index_clause " { set cname($attnum) $column_name } foreach indid [split $indkey " "] { if {[info exists cname($indid)]} { append return_string $sep$cname($indid) set sep ", " } } append return_string ");" unset -nocomplain cname } return $return_stringXQL Not present: Generic, PostgreSQL, Oracle