Updating cidr column with network operator

From: Axel Rau <Axel(dot)Rau(at)Chaos1(dot)DE>
To: pgsql-sql(at)postgresql(dot)org
Subject: Updating cidr column with network operator
Date: 2005-09-22 10:52:16
Message-ID: ffaabb4676ab075beb4b6d041ec280c4@Chaos1.DE
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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):
UPDATE address
SET network = (SELECT N.id WHERE A.id << N.id)
FROM address A, network N
WHERE A.id << N.id;

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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Hannes Dorbath 2005-09-22 12:12:09 Re: Copy Views From Database?
Previous Message Hannes Dorbath 2005-09-22 09:08:21 Re: Copy Views From Database?