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 6F03CDA7D3 for ; Thu, 22 Sep 2005 11:43:51 -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 88830-05 for ; Thu, 22 Sep 2005 14:43:46 +0000 (GMT) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by svr1.postgresql.org (Postfix) with ESMTP id 0335EDA782 for ; Thu, 22 Sep 2005 11:43:48 -0300 (ADT) Received: from website.brandywine.com (mailcheck.brandywine.com [146.145.113.9]) by svr4.postgresql.org (Postfix) with ESMTP id 1B2B55AF6CA for ; Thu, 22 Sep 2005 14:43:53 +0000 (GMT) X-eSCM-MailFrom: Received: from BAM_EXCHANGE (10.1.0.100) by website.brandywine.com (10.1.0.9); Thu, 22 September 2005 10:46:27 -0400 Received: from [10.1.0.60] (gen-wayne [10.1.0.60]) by bam_exchange.brandywine.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id R6ZYXRWK; Thu, 22 Sep 2005 10:44:27 -0400 Message-ID: <4332C38E.5040807@brandywine.com> Date: Thu, 22 Sep 2005 10:45:34 -0400 From: Daryl Richter Reply-To: daryl@brandywine.com Organization: Brandywine Asset Management User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Updating cidr column with network operator References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 required=5 tests=[none] X-Spam-Level: X-Archive-Number: 200509/206 X-Sequence-Number: 22753 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? > 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" ... > But this ended up with all network columns pointing at the same net (-:). > Any help would be appreciated. > > Axel > Axel Rau, Frankfurt, Germany +49-69-951418-0 > > > ---------------------------(end of broadcast)--------------------------- > TIP 9: In versions below 8.0, the planner will ignore your desire to > choose an index scan if your joining column's datatypes do not > match -- Daryl "We want great men who, when fortune frowns, will not be discouraged." -- Colonel Henry Knox, 1776