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 31E7CDAAB9 for ; Thu, 22 Sep 2005 14:58:55 -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 89390-09 for ; Thu, 22 Sep 2005 17:58:48 +0000 (GMT) Received: from mail1.chaos1.de (Mail1.Chaos1.de [213.160.12.53]) by svr1.postgresql.org (Postfix) with ESMTP id 55B2BDAA86 for ; Thu, 22 Sep 2005 14:58:45 -0300 (ADT) Received: from claudius6.in.chaos1.de ([192.168.220.106]) by mail1.chaos1.de with esmtpsa (TLSv1:RC4-SHA:128) (Exim 4.44) id 1EIVLJ-0000m4-5f; Thu, 22 Sep 2005 19:58:45 +0200 In-Reply-To: <4332C38E.5040807@brandywine.com> References: <4332C38E.5040807@brandywine.com> Mime-Version: 1.0 (Apple Message framework v622) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: <72c14f47f1dca0ae99e559cef56416a3@Chaos1.DE> Content-Transfer-Encoding: 7bit Cc: pgsql-sql@postgresql.org From: Axel Rau Subject: Re: Updating cidr column with network operator Date: Thu, 22 Sep 2005 19:58:34 +0200 To: daryl@brandywine.com X-Mailer: Apple Mail (2.622) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.013 required=5 tests=[AWL=0.013] X-Spam-Level: X-Archive-Number: 200509/209 X-Sequence-Number: 22756 Thank you for responding, Daryl, Am 22.09.2005 um 16:45 schrieb Daryl Richter: > Axel Rau wrote: >> Hi SQLers, >> I have a fk from address to network and try to update the foreign key >> column to point at the network, "it belongs to": >> CREATE TABLE network ( >> id cidr PRIMARY KEY , -- 'PK, ,IPv4/6 Network address' >> ) >> CREATE TABLE address ( >> id inet PRIMARY KEY , -- 'PK of IPv4/6 host >> address' >> network cidr NOT NULL -- 'FK to Network table' >> REFERENCES network ON DELETE CASCADE ON UPDATE >> CASCADE >> ) >> I tried (using the WHERE clause to eliminate the addresses were no >> corresponding net exists): > > But you can't insert a row in address w/o a valid network.id? That's > what the fk ensures. > > Perhaps you could elaborate more? Are you trying to *put* on the fk > and you currently have bad data? The fk requires a corresponding row in network. But my update tries to reference the right network, that one where the ip address belongs to. > >> UPDATE address >> SET network = (SELECT N.id WHERE A.id << N.id) >> FROM address A, network N >> WHERE A.id << N.id; > > This also makes no sense. For starters, << is "bitwise shift left" ... I'm using 8.0.3 and there are some new operators related to inet and cidr data types. On page 157, I found "<<" as address/network "is contained in" network. Finding the net where an address belongs to works as: SELECT id FROM network WHERE inet '$p_ipSource' << id; Axel Axel Rau, Frankfurt, Germany +49-69-951418-0