pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Axel Rau <Axel.Rau@Chaos1.DE>
To: daryl@brandywine.com
Cc: pgsql-sql@postgresql.org
Subject: Re: Updating cidr column with network operator
Date: Thu, 22 Sep 2005 19:58:34 +0200
Message-ID: <72c14f47f1dca0ae99e559cef56416a3@Chaos1.DE> (raw)
In-Reply-To: <4332C38E.5040807@brandywine.com>
References: <ffaabb4676ab075beb4b6d041ec280c4@Chaos1.DE>
	<4332C38E.5040807@brandywine.com>

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




view thread (16+ messages)  latest in thread

Message-ID: <72c14f47f1dca0ae99e559cef56416a3@Chaos1.DE>
Permalink:  ../72c14f47f1dca0ae99e559cef56416a3@Chaos1.DE/
Also on:    postgresql.org/message-id/72c14f47f1dca0ae99e559cef56416a3@Chaos1.DE

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: Axel.Rau@Chaos1.DE, daryl@brandywine.com
  Subject: Re: Updating cidr column with network operator
  In-Reply-To: <72c14f47f1dca0ae99e559cef56416a3@Chaos1.DE>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox