Thread: How to drop all the sequences

How to drop all the sequences

From
"Arunachalam Jaisankar"
Date:
I found sequences are not getting dropped when tables are dropped. It is too difficult to drop all sequences one by one manually. Is there any command to drop all sequences in a database? Looking for help.
 
regards
Jaisankar
 
 

Re: How to drop all the sequences

From
Neil Conway
Date:
On Thu, 2003-02-20 at 11:40, Arunachalam Jaisankar wrote:
> I found sequences are not getting dropped when tables are dropped.

SERIAL sequences should automatically be dropped with their
corresponding table in PostgreSQL 7.3.0 and later.

> It is too difficult to drop all sequences one by one manually. Is
> there any command to drop all sequences in a database?

No. You could try iterating through pg_class, picking out the sequence
relations (relkind = 'S') in the right database, and then dropping the
sequences that way.

Cheers,

Neil
--
Neil Conway <neilc@samurai.com> || PGP Key ID: DB3C29FC




Re: How to drop all the sequences

From
"Berend Tober"
Date:
> On Thu, 2003-02-20 at 11:40, Arunachalam Jaisankar wrote:
>
>> It is too difficult to drop all sequences one by one manually. Is
>> there any command to drop all sequences in a database?
>
> No. You could try iterating through pg_class, picking out the sequence
> relations (relkind = 'S') in the right database, and then dropping the
> sequences that way.
>

This is what I do:

Save the output of

SELECT 'drop sequence ' || c.relname || ';' FROM pg_class c WHERE
(c.relkind = 'S');

to a file and then run that.

~Berend Tober




Re: How to drop all the sequences

From
Bruce Momjian
Date:
Neil Conway wrote:
> On Thu, 2003-02-20 at 11:40, Arunachalam Jaisankar wrote:
> > I found sequences are not getting dropped when tables are dropped.
>
> SERIAL sequences should automatically be dropped with their
> corresponding table in PostgreSQL 7.3.0 and later.
>
> > It is too difficult to drop all sequences one by one manually. Is
> > there any command to drop all sequences in a database?
>
> No. You could try iterating through pg_class, picking out the sequence
> relations (relkind = 'S') in the right database, and then dropping the
> sequences that way.

As I remember, a 7.2 database loaded into 7.3 doesn't have the
dependency linkage.  /contrib/adddepend adds such linkage in 7.3 for
pre-7.3 database loaded into 7.3.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073