Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VfdEq-00031B-S2 for pgsql-hackers@arkaria.postgresql.org; Sun, 10 Nov 2013 22:12:13 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VfdEq-0001r2-4H for pgsql-hackers@arkaria.postgresql.org; Sun, 10 Nov 2013 22:12:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VfdEo-0001qZ-T8 for pgsql-hackers@postgresql.org; Sun, 10 Nov 2013 22:12:10 +0000 Received: from moutng.kundenserver.de ([212.227.17.9]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VfdEk-0002Iz-5k for pgsql-hackers@postgresql.org; Sun, 10 Nov 2013 22:12:08 +0000 Received: from anarazel.de (p5DDC55B8.dip0.t-ipconnect.de [93.220.85.184]) by mrelayeu.kundenserver.de (node=mreu2) with ESMTP (Nemesis) id 0M2pmM-1VPt2M2aYA-00sjqG; Sun, 10 Nov 2013 23:12:00 +0100 Received: by anarazel.de (Postfix, from userid 1000) id D8DA61024D3; Sun, 10 Nov 2013 23:11:59 +0100 (CET) Date: Sun, 10 Nov 2013 23:11:59 +0100 From: Andres Freund To: Tom Lane Cc: Tomas Vondra , pgsql-hackers@postgresql.org Subject: Re: Re: [BUGS] BUG #7873: pg_restore --clean tries to drop tables that don't exist Message-ID: <20131110221159.GD32665@awork2.anarazel.de> References: <5236B11B.8040700@uptime.jp> <5256DBBF.8010605@dunslane.net> <20131014214421.GE25013@awork2.anarazel.de> <525C6ED3.9090701@fuzzy.cz> <20131014222800.GH25013@awork2.anarazel.de> <3210.1384118907@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3210.1384118907@sss.pgh.pa.us> X-Provags-ID: V02:K0:eM+NuCnT+X6FgZL4HJu7TaLocXt+c8a0LNRI1Hon+bP ju44//nTthPUhLHruT/1btet2TsBK9qQsvOp1rE4/ZWF42F9YI 8Ie167MLwmRtenkPj28Vz5/WlSHsk2+go8GbKLkdbyMiHQ6WmV zSpSDzpYekDylGpNOfVOWynMXlWfpkz1P9ZWSgdvIdVCtt3O5d OVjcXGrWCiRUPm0al6Vm7h4ssz8Yvn/Rv4qX6OVS1G/53GhMcx QASdoO9Ezs0Cp4eU/g/b4fGIb05+fo0GXY8E3FJ30J4iIddCTQ Uqlho+5F74simzRHF8hLUh4Tlno+cofiW/1c0s39z6mMlJXhiL LpPdoNpa96GfL8dvKx5kHKdrFjUkxOmyN4NAvDtJD X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 2013-11-10 16:28:27 -0500, Tom Lane wrote: > [ catching up on old email ] > > Andres Freund writes: > > On 2013-10-15 00:23:15 +0200, Tomas Vondra wrote: > >> On 2013-10-10 12:54:23 -0400, Andrew Dunstan wrote: > >>> This thread seems to have gone cold, but I'm inclined to agree with > >>> Pavel. If the table doesn't exist, neither does the trigger, and > >>> the whole point of the 'IF EXISTS' variants is to provide the > >>> ability to issue DROP commands that don't fail if their target is > >>> missing. > > >> -1, this seems to likely to just hide typos. > > > Because there simply is no reason to issue a DROP TRIGGER IF EXISTS if > > you don't need the contents of the table. In that case you can just > > issue a DROP TABLE IF EXISTS and start anew. > > I think this is nonsense. It's only one step removed from "why do you > need IF EXISTS at all, you should know whether the object is there". > The entire point of this syntax is to not need to do detailed analysis > about whether the object is there. Well, in my opinion the IF EXISTS refers to the object type being dropped. I.e. with DROP TABLE it refers to the table not existing, with DROP TRIGGER it refers to the trigger not existing. Note how we also error out if you do something like: ALTER TABLE nonexistant DROP COLUMN IF EXISTS bar; > The pg_dump --clean use-case is sufficient refutation for that, IMO. > You're suggesting that pg_dump should make a special case out of what it > emits for "cleaning" a trigger; which we could do I guess, but it would be > ugly and fragile. For instance, the special case would probably soon grow > some warts for partial-dump scenarios. ISTM the only way to get a DROP TRIGGER that actually is required is a --section=post-data dump. In the other cases it will get dropped by the DROP TABLE that's executed shortly afterwards. But in that case we'll currently error out during the CREATE TRIGGER shortly afterwards if the table doesn't exist... Maybe the way to fix this properly is to not drop post-data objects that are implicitly dropped by the object that owns them. >Anyway, pg_dump is not the only tool that might wish to use DROP IF EXISTS. Well, I am absolutely not arguing against DROP TRIGGER IF NOT EXISTS (which we already have), just against it ignoring nonexistant tables instead of just nonexistant triggers. Greetings, Andres Freund -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers