pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Drop all indexes of a table w/o knowing the index names
3+ messages / 2 participants
[nested] [flat]

* Drop all indexes of a table w/o knowing the index names
@ 2004-11-09 14:40 Giulio Orsero <giulioo@pobox.com>
  2004-11-09 15:30 ` Re: Drop all indexes of a table w/o knowing the index names Achilleus Mantzios <achill@matrix.gatewaynet.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Giulio Orsero @ 2004-11-09 14:40 UTC (permalink / raw)
  To: pgsql-sql

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@pobox.com



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Drop all indexes of a table w/o knowing the index names
  2004-11-09 14:40 Drop all indexes of a table w/o knowing the index names Giulio Orsero <giulioo@pobox.com>
@ 2004-11-09 15:30 ` Achilleus Mantzios <achill@matrix.gatewaynet.com>
  2004-11-09 19:55   ` Re: Drop all indexes of a table w/o knowing the index names Giulio Orsero <giulioo@pobox.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Achilleus Mantzios @ 2004-11-09 15:30 UTC (permalink / raw)
  To: Giulio Orsero <giulioo@pobox.com>; +Cc: pgsql-sql

O Giulio Orsero Ýãñáøå óôéò Nov 9, 2004 :

> 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

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

-- 
-Achilleus




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Drop all indexes of a table w/o knowing the index names
  2004-11-09 14:40 Drop all indexes of a table w/o knowing the index names Giulio Orsero <giulioo@pobox.com>
  2004-11-09 15:30 ` Re: Drop all indexes of a table w/o knowing the index names Achilleus Mantzios <achill@matrix.gatewaynet.com>
@ 2004-11-09 19:55   ` Giulio Orsero <giulioo@pobox.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Giulio Orsero @ 2004-11-09 19:55 UTC (permalink / raw)
  To: Achilleus Mantzios <achill@matrix.gatewaynet.com>; +Cc: pgsql-sql

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

>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@pobox.com



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2004-11-09 19:55 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-11-09 14:40 Drop all indexes of a table w/o knowing the index names Giulio Orsero <giulioo@pobox.com>
2004-11-09 15:30 ` Achilleus Mantzios <achill@matrix.gatewaynet.com>
2004-11-09 19:55   ` Giulio Orsero <giulioo@pobox.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox