truncate all tables?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

truncate all tables?

Zlatko Matic
How could I truncate, delete all content of all tables in one step ?
Reply | Threaded
Open this post in threaded view
|

Re: truncate all tables?

Michael Glaesemann

On Jun 29, 2005, at 6:34 PM, Zlatko Matić wrote:

> How could I truncate, delete all content of all tables in one step ?

The PostgreSQL documentation is quite good. I recommend looking  
through it.

http://www.postgresql.org/docs/8.0/interactive/index.html

In particular, here:
http://www.postgresql.org/docs/8.0/interactive/sql-truncate.html

Google works pretty well also:

http://www.google.com/search?biw=892&hl=en&q=postgresql 
+truncate&btnG=Google+Search

Hope this helps.

Michael Glaesemann
grzm myrealbox com



---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match
Reply | Threaded
Open this post in threaded view
|

Re: truncate all tables?

Richard Huxton
In reply to this post by Zlatko Matic
Zlatko Matić wrote:
> How could I truncate, delete all content of all tables in one step ?

Something like this?

pg_dump --schema-only mydb > mydb.schema.dump
dropdb mydb
psql -f mydb.schema.dump mydb

--
   Richard Huxton
   Archonet Ltd


---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings
Reply | Threaded
Open this post in threaded view
|

Re: truncate all tables?

Michael Glaesemann

On Jun 29, 2005, at 7:04 PM, Richard Huxton wrote:

> Zlatko Matić wrote:
>
>> How could I truncate, delete all content of all tables in one step ?
>>
>
> Something like this?
>
> pg_dump --schema-only mydb > mydb.schema.dump
> dropdb mydb
> psql -f mydb.schema.dump mydb

That's nice!

Michael Glaesemann
grzm myrealbox com



---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match
Reply | Threaded
Open this post in threaded view
|

Re: truncate all tables?

Doug Bloebaum
In reply to this post by Zlatko Matic
On 6/29/05, Zlatko Matić <[hidden email]> wrote:
>  
> How could I truncate, delete all content of all tables in one step ?

You could use a query to generate the statements in psql:

\t
\o trunc_all.out

SELECT 'TRUNCATE ' || table_name || ';'
  FROM information_schema.tables
 WHERE table_schema='my_schema_name'
   AND table_type='BASE TABLE';

\t
\o

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

               http://archives.postgresql.org