<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: PostgreSQL, SQLAlchemy, Dropping all tables and sequences</title>
	<atom:link href="http://www.luckydonkey.com/2007/11/23/postgresql-sqlalchemy-dropping-all-tables-and-sequences/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.luckydonkey.com/2007/11/23/postgresql-sqlalchemy-dropping-all-tables-and-sequences/</link>
	<description>Never knowingly knowing narwhals</description>
	<lastBuildDate>Sun, 04 Sep 2011 22:12:45 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: mike bayer</title>
		<link>http://www.luckydonkey.com/2007/11/23/postgresql-sqlalchemy-dropping-all-tables-and-sequences/comment-page-1/#comment-2564</link>
		<dc:creator>mike bayer</dc:creator>
		<pubDate>Wed, 15 Sep 2010 13:54:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.luckydonkey.com/2007/11/23/postgresql-sqlalchemy-dropping-all-tables-and-sequences/#comment-2564</guid>
		<description>hiya -

Just saw this post tweeted so here&#039;s an update.  I have the ultimate &quot;drop everything&quot; script that now uses the Inspector to pull everything in - so far I&#039;ve tested with Postgresql and MS-SQL.    Though currently its doing just all the tables and related objects - I notice Pavel&#039;s script does views and routines too.   http://www.sqlalchemy.org/trac/wiki/UsageRecipes/DropEverything</description>
		<content:encoded><![CDATA[<p>hiya -</p>
<p>Just saw this post tweeted so here&#8217;s an update.  I have the ultimate &#8220;drop everything&#8221; script that now uses the Inspector to pull everything in &#8211; so far I&#8217;ve tested with Postgresql and MS-SQL.    Though currently its doing just all the tables and related objects &#8211; I notice Pavel&#8217;s script does views and routines too.   <a href="http://www.sqlalchemy.org/trac/wiki/UsageRecipes/DropEverything" rel="nofollow">http://www.sqlalchemy.org/trac/wiki/UsageRecipes/DropEverything</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pavel Sedek</title>
		<link>http://www.luckydonkey.com/2007/11/23/postgresql-sqlalchemy-dropping-all-tables-and-sequences/comment-page-1/#comment-2555</link>
		<dc:creator>Pavel Sedek</dc:creator>
		<pubDate>Thu, 22 Jul 2010 18:16:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.luckydonkey.com/2007/11/23/postgresql-sqlalchemy-dropping-all-tables-and-sequences/#comment-2555</guid>
		<description>Hello, here is an easy solution in plpgsql. You can then drop all views, sequences, tables and functions just with calling SELECT drop_db();

Method declaration:

CREATE OR REPLACE FUNCTION drop_db()
  RETURNS void AS
$BODY$
  DECLARE
    objname character varying;
  
  BEGIN

	FOR objname IN SELECT table_name FROM information_schema.views WHERE table_schema = &#039;public&#039; LOOP
		EXECUTE &#039;DROP VIEW &#039; &#124;&#124; objname ;
	END LOOP;
	
	FOR objname IN SELECT table_name FROM information_schema.tables WHERE table_schema = &#039;public&#039; LOOP
		EXECUTE &#039;DROP TABLE &#039; &#124;&#124; objname &#124;&#124; &#039; CASCADE &#039;;
	END LOOP;

	FOR objname IN SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema = &#039;public&#039; LOOP
		EXECUTE &#039;DROP SEQUENCE &#039; &#124;&#124; objname &#124;&#124; &#039; CASCADE &#039;;
	END LOOP;

	FOR objname IN SELECT routine_name FROM information_schema.routines WHERE routine_schema = &#039;public&#039; LOOP
		CONTINUE WHEN objname = &#039;drop_db&#039;;
		EXECUTE &#039;DROP FUNCTION &#039; &#124;&#124; objname &#124;&#124; &#039;() &#039; ;
	END LOOP;
	
END;
$BODY$
  LANGUAGE &#039;plpgsql&#039; VOLATILE
  COST 100;</description>
		<content:encoded><![CDATA[<p>Hello, here is an easy solution in plpgsql. You can then drop all views, sequences, tables and functions just with calling SELECT drop_db();</p>
<p>Method declaration:</p>
<p>CREATE OR REPLACE FUNCTION drop_db()<br />
  RETURNS void AS<br />
$BODY$<br />
  DECLARE<br />
    objname character varying;</p>
<p>  BEGIN</p>
<p>	FOR objname IN SELECT table_name FROM information_schema.views WHERE table_schema = &#8216;public&#8217; LOOP<br />
		EXECUTE &#8216;DROP VIEW &#8216; || objname ;<br />
	END LOOP;</p>
<p>	FOR objname IN SELECT table_name FROM information_schema.tables WHERE table_schema = &#8216;public&#8217; LOOP<br />
		EXECUTE &#8216;DROP TABLE &#8216; || objname || &#8216; CASCADE &#8216;;<br />
	END LOOP;</p>
<p>	FOR objname IN SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema = &#8216;public&#8217; LOOP<br />
		EXECUTE &#8216;DROP SEQUENCE &#8216; || objname || &#8216; CASCADE &#8216;;<br />
	END LOOP;</p>
<p>	FOR objname IN SELECT routine_name FROM information_schema.routines WHERE routine_schema = &#8216;public&#8217; LOOP<br />
		CONTINUE WHEN objname = &#8216;drop_db&#8217;;<br />
		EXECUTE &#8216;DROP FUNCTION &#8216; || objname || &#8216;() &#8216; ;<br />
	END LOOP;</p>
<p>END;<br />
$BODY$<br />
  LANGUAGE &#8216;plpgsql&#8217; VOLATILE<br />
  COST 100;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sequnecen l?schen - PG-Forum.de</title>
		<link>http://www.luckydonkey.com/2007/11/23/postgresql-sqlalchemy-dropping-all-tables-and-sequences/comment-page-1/#comment-2528</link>
		<dc:creator>Sequnecen l?schen - PG-Forum.de</dc:creator>
		<pubDate>Tue, 10 Nov 2009 12:40:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.luckydonkey.com/2007/11/23/postgresql-sqlalchemy-dropping-all-tables-and-sequences/#comment-2528</guid>
		<description>[...] * from information_schema.sequences; mit Hilfe von google bei www.luckydonkey.com [...]</description>
		<content:encoded><![CDATA[<p>[...] * from information_schema.sequences; mit Hilfe von google bei <a href="http://www.luckydonkey.com" rel="nofollow">http://www.luckydonkey.com</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: table coverzz</title>
		<link>http://www.luckydonkey.com/2007/11/23/postgresql-sqlalchemy-dropping-all-tables-and-sequences/comment-page-1/#comment-2342</link>
		<dc:creator>table coverzz</dc:creator>
		<pubDate>Mon, 15 Sep 2008 20:05:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.luckydonkey.com/2007/11/23/postgresql-sqlalchemy-dropping-all-tables-and-sequences/#comment-2342</guid>
		<description>oh i guess that i what i was doing wrong Rick thanks for the tip</description>
		<content:encoded><![CDATA[<p>oh i guess that i what i was doing wrong Rick thanks for the tip</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick Copeland</title>
		<link>http://www.luckydonkey.com/2007/11/23/postgresql-sqlalchemy-dropping-all-tables-and-sequences/comment-page-1/#comment-1990</link>
		<dc:creator>Rick Copeland</dc:creator>
		<pubDate>Mon, 07 Jan 2008 20:09:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.luckydonkey.com/2007/11/23/postgresql-sqlalchemy-dropping-all-tables-and-sequences/#comment-1990</guid>
		<description>drop_all() doesn&#039;t actually work if there are circular ForeignKey dependences in PostgreSQL.  I have a short explanation (and quick fix) at http://pythonisito.blogspot.com/2008/01/cascading-drop-table-with-sqlalchemy.html</description>
		<content:encoded><![CDATA[<p>drop_all() doesn&#8217;t actually work if there are circular ForeignKey dependences in PostgreSQL.  I have a short explanation (and quick fix) at <a href="http://pythonisito.blogspot.com/2008/01/cascading-drop-table-with-sqlalchemy.html" rel="nofollow">http://pythonisito.blogspot.com/2008/01/cascading-drop-table-with-sqlalchemy.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mike bayer</title>
		<link>http://www.luckydonkey.com/2007/11/23/postgresql-sqlalchemy-dropping-all-tables-and-sequences/comment-page-1/#comment-1975</link>
		<dc:creator>mike bayer</dc:creator>
		<pubDate>Mon, 03 Dec 2007 04:10:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.luckydonkey.com/2007/11/23/postgresql-sqlalchemy-dropping-all-tables-and-sequences/#comment-1975</guid>
		<description>hiya -

sqlalchemy drops tables in order of dependency, where by &quot;dependency&quot; we mean foreign key dependencies..you can declare these explicitly using the ForeignKey construct.  But table reflection already uses the PG system tables to get this information automatically (we used to use information_schema but it proved to be too slow and quirky).  this feature can be used to drop all tables in the correct order like so:

engine = create_engine(&quot;posgres://user:pass@host/db&quot;)
meta = MetaData(engine)
meta.reflect()
meta.drop_all()

however, it currently doesn&#039;t cover sequences except for those which were created implicitly using SERIAL columns...we might add support for reflection of external sequences eventually.

- mike</description>
		<content:encoded><![CDATA[<p>hiya -</p>
<p>sqlalchemy drops tables in order of dependency, where by &#8220;dependency&#8221; we mean foreign key dependencies..you can declare these explicitly using the ForeignKey construct.  But table reflection already uses the PG system tables to get this information automatically (we used to use information_schema but it proved to be too slow and quirky).  this feature can be used to drop all tables in the correct order like so:</p>
<p>engine = create_engine(&#8220;posgres://user:pass@host/db&#8221;)<br />
meta = MetaData(engine)<br />
meta.reflect()<br />
meta.drop_all()</p>
<p>however, it currently doesn&#8217;t cover sequences except for those which were created implicitly using SERIAL columns&#8230;we might add support for reflection of external sequences eventually.</p>
<p>- mike</p>
]]></content:encoded>
	</item>
</channel>
</rss>

