X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 204B3D920C for ; Fri, 23 Sep 2005 14:32:49 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 31689-02 for ; Fri, 23 Sep 2005 17:32:46 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id BBD08D8D48 for ; Fri, 23 Sep 2005 14:32:43 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j8NHW5pt058568 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 23 Sep 2005 11:32:07 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.3/8.13.3) with ESMTP id j8NHW5Yh081109; Fri, 23 Sep 2005 11:32:05 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.3/8.13.3/Submit) id j8NHW4D0081108; Fri, 23 Sep 2005 11:32:04 -0600 (MDT) (envelope-from mfuhr) Date: Fri, 23 Sep 2005 11:32:04 -0600 From: Michael Fuhr To: Axel Rau Cc: daryl@brandywine.com, pgsql-sql@postgresql.org Subject: Re: Updating cidr column with network operator Message-ID: <20050923173204.GA80995@winnie.fuhr.org> References: <4332C38E.5040807@brandywine.com> <72c14f47f1dca0ae99e559cef56416a3@Chaos1.DE> <43331359.1020703@brandywine.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200509/234 X-Sequence-Number: 22781 On Fri, Sep 23, 2005 at 06:31:17PM +0200, Axel Rau wrote: > Networks change during time, being diveded or aggregated or you just > enter wrong data during insert. Have you considered using a CHECK constraint and/or a trigger to ensure that the network in the network column contains the address in the id column? If you have and rejected the idea, what were the reasons? > With the UPDATE below, I want to correct the addresses to again point > at the right net. Does the following statement do what you want? It shouldn't touch the records with no matching network -- what do you want to happen in those cases? This update also might not give the results you want if more than one network matches. UPDATE address SET network = n.id FROM network n WHERE address.id << n.id; > While writing this, I learn that because of the pk in network, > UPDATEs will be difficult to accomplish (you may need a temporary > net to park all addresses of a network to be divided, make the > change in network and use the UPDATE below to adjust A.network. I > use net '0.0.0.0/32' as 'UNKNOWN' net or for parking. I'm not sure I understand what you're saying, but if you're concerned about foreign key violations then making the foreign key constraints deferrable and deferring them during certain updates might remove the need for a temporary "parking" network. -- Michael Fuhr