dbTalk Databases Forums  

Drop all indexes of a table w/o knowing the index names

comp.databases.postgresql.sql comp.databases.postgresql.sql


Discuss Drop all indexes of a table w/o knowing the index names in the comp.databases.postgresql.sql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Giulio Orsero
 
Posts: n/a

Default Drop all indexes of a table w/o knowing the index names - 11-09-2004 , 08:40 AM






7.4.6 on Linux.

I need a way to drop all indexes of a table without knowing the names of the
indexes.

Say I have a table

table1
index1
index2
index3

I don't want to do

drop index1;
drop index2;
drop index3;

but I want

drop <all indexes of table table1>

is this possible? I looked in the manual at pg_index, but couldn't build an
sql string to do it.

Thanks

--
giulioo (AT) pobox (DOT) com

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings


Reply With Quote
  #2  
Old   
Achilleus Mantzios
 
Posts: n/a

Default Re: Drop all indexes of a table w/o knowing the index names - 11-09-2004 , 09:30 AM






O Giulio Orsero έγραψε στις Nov 9, 2004 :

Quote:
7.4.6 on Linux.

I need a way to drop all indexes of a table without knowing the names of the
indexes.

Say I have a table

table1
index1
index2
index3

I don't want to do

drop index1;
drop index2;
drop index3;

but I want

drop <all indexes of table table1
if your are using default namespace (schema)
% tcsh

% foreach i ( `psql -t -q -c "SELECT ci.relname from pg_index i,pg_class
ci,pg_class ct where i.indexrelid=ci.oid and i.indrelid=ct.oid and
ct.relname='YOUR_TABLE_HERE'"` )
foreach? psql -c "drop index $i"
foreach? end

Quote:
is this possible? I looked in the manual at pg_index, but couldn't build an
sql string to do it.

Thanks


--
-Achilleus


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html



Reply With Quote
  #3  
Old   
Giulio Orsero
 
Posts: n/a

Default Re: Drop all indexes of a table w/o knowing the index names - 11-09-2004 , 01:55 PM



On Tue, 9 Nov 2004 17:30:25 +0200 (EET), Achilleus Mantzios
<achill (AT) matrix (DOT) gatewaynet.com> wrote:

Quote:
O Giulio Orsero έγραψε στις Nov 9, 2004 :
I need a way to drop all indexes of a table without knowing the names of the
indexes.

% foreach i ( `psql -t -q -c "SELECT ci.relname from pg_index i,pg_class
ci,pg_class ct where i.indexrelid=ci.oid and i.indrelid=ct.oid and
ct.relname='YOUR_TABLE_HERE'"` )
foreach? psql -c "drop index $i"
foreach? end
Ok, worked as expected.

thanks

--
giulioo (AT) pobox (DOT) com

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.