<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Forum — Script to clean out old records]]></title>
		<link>https://forums.nbn.org.uk/viewtopic.php?id=1513</link>
		<atom:link href="https://forums.nbn.org.uk/extern.php?action=feed&amp;tid=1513&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Script to clean out old records.]]></description>
		<lastBuildDate>Thu, 20 May 2010 11:05:07 +0000</lastBuildDate>
		<generator>PunBB 1.4.6</generator>
		<item>
			<title><![CDATA[Re: Script to clean out old records]]></title>
			<link>https://forums.nbn.org.uk/viewtopic.php?pid=6502#p6502</link>
			<description><![CDATA[<p>Ah!</p><p>1) I should have figured that for myself.</p><p>2) All works fine now - thanks!</p><p>All the best</p><p>Alan</p>]]></description>
			<author><![CDATA[null@example.com (Alan Hale)]]></author>
			<pubDate>Thu, 20 May 2010 11:05:07 +0000</pubDate>
			<guid>https://forums.nbn.org.uk/viewtopic.php?pid=6502#p6502</guid>
		</item>
		<item>
			<title><![CDATA[Re: Script to clean out old records]]></title>
			<link>https://forums.nbn.org.uk/viewtopic.php?pid=6499#p6499</link>
			<description><![CDATA[<p>Hi Alan<br />1) Its not the database name, but the schema name you need to prefix. Assuming you used the default indicia schema during installation, the samples table is actually indicia.samples. To avoid having to specify it for each query, run the following first:<br /></p><div class="codebox"><pre><code>SET search_path=indicia, public;</code></pre></div><p>.<br />2) Ah, er. Ahem, I seem to have copied in my script in the wrong order. Oops. I&#039;ve edited the original post.</p><p>Best Wishes</p>]]></description>
			<author><![CDATA[null@example.com (johnvanbreda)]]></author>
			<pubDate>Thu, 20 May 2010 07:45:44 +0000</pubDate>
			<guid>https://forums.nbn.org.uk/viewtopic.php?pid=6499#p6499</guid>
		</item>
		<item>
			<title><![CDATA[Re: Script to clean out old records]]></title>
			<link>https://forums.nbn.org.uk/viewtopic.php?pid=6496#p6496</link>
			<description><![CDATA[<p>John - a couple of issues:</p><p>1. In PgAdminIII I find I have to prefix the table names with the database name (even though the correct database is selcted in the main window);</p><p>2. More problematically, I get an error:</p><p>ERROR:&nbsp; update or delete on table &quot;samples&quot; violates foreign key constraint &quot;fk_occurrence_sample&quot; on table &quot;occurrences&quot;<br />DETAIL:&nbsp; Key (id) =&nbsp; (4) is still referenced from table &quot;occurrences&quot;.</p><p>All the best</p><p>Alan</p>]]></description>
			<author><![CDATA[null@example.com (Alan Hale)]]></author>
			<pubDate>Wed, 19 May 2010 14:07:23 +0000</pubDate>
			<guid>https://forums.nbn.org.uk/viewtopic.php?pid=6496#p6496</guid>
		</item>
		<item>
			<title><![CDATA[Re: Script to clean out old records]]></title>
			<link>https://forums.nbn.org.uk/viewtopic.php?pid=6478#p6478</link>
			<description><![CDATA[<p>Thanks John - I have been meaning to ask you for something like this and it will definitely be useful.</p><p>Cheers</p><p>Alan</p>]]></description>
			<author><![CDATA[null@example.com (Alan Hale)]]></author>
			<pubDate>Sun, 16 May 2010 09:02:06 +0000</pubDate>
			<guid>https://forums.nbn.org.uk/viewtopic.php?pid=6478#p6478</guid>
		</item>
		<item>
			<title><![CDATA[Re: Script to clean out old records]]></title>
			<link>https://forums.nbn.org.uk/viewtopic.php?pid=6463#p6463</link>
			<description><![CDATA[<p>In case it is of use to anyone (or me in the future!) here is a script that can be run against postgreSQL to remove records entered into a survey before a specified date:<br /></p><div class="codebox"><pre><code>delete from occurrence_attribute_values where id in (
select oav.id
from occurrence_attribute_values oav
inner join occurrences o on o.id=oav.occurrence_id
inner join samples s on s.id=o.sample_id
where s.survey_id=7 
and s.created_on &lt; &#039;2010-04-22&#039;);

delete from sample_attribute_values where id in (
select sav.id
from sample_attribute_values sav
inner join samples s on s.id=sav.sample_id
where s.survey_id=7 
and s.created_on &lt; &#039;2010-04-22&#039;);

delete from occurrences
where sample_id in
 (select id from samples where survey_id=7 
and created_on &lt; &#039;2010-04-22&#039;);

delete from samples where survey_id=7 
and created_on &lt; &#039;2010-04-22&#039;;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (johnvanbreda)]]></author>
			<pubDate>Wed, 12 May 2010 08:07:05 +0000</pubDate>
			<guid>https://forums.nbn.org.uk/viewtopic.php?pid=6463#p6463</guid>
		</item>
	</channel>
</rss>
