getting inet out of char?

From: Andrew Sullivan <sullivana(at)bpl(dot)on(dot)ca>
To: user Postgresql ML <pgsql-general(at)postgresql(dot)org>
Subject: getting inet out of char?
Date: 2000-06-06 20:38:24
Message-ID: 20000606163824.F25986@bpl.on.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

Since everyone here has been so helpful in the past (even when I recently
overlooked something obvious in The Fine Material), I wonder if I might get
a pointer about what to do in this case.

I have a table mapping names to ips; the access to users is through PHP3.
Now, PHP's module to PostgreSQL does not know about the data type inet. I
could just forget about it, but it seems to me the inet data type offers a
number of advantages for easy data extraction. So, I thought the answer
would be simple: I created two tables.

Table "name_and_ip"
Attribute | Type | Modifier
-----------+-------------+----------
name | varchar(30) | not null
ip | char(15) | not null
Indices: name_and_ip_ip_key,
name_and_ip_name_key

Table "name_and_ip_v4"
Attribute | Type | Modifier
-----------+-------------+----------
name | varchar(30) | not null
ip | inet | not null
Indices: name_and_ip_v4_ip_key,
name_and_ip_v4_name_key

And I thought to have a rule:

create rule name_ip_update as on update to name_and_ip do insert into
name_and_ip_v4(name,ip) values (new.name, new.ip::inet);
ERROR: Cannot cast type 'bpchar' to 'inet'

Is there something else I can do? (Having followed the recent discussion on
rules and triggers, I thought a rule was what I wanted.)

Thanks,
A

--
Andrew Sullivan Computer Services
<sullivana(at)bpl(dot)on(dot)ca> Burlington Public Library
+1 905 639 3611 x158 2331 New Street
Burlington, Ontario, Canada L7R 1J4

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2000-06-06 21:20:06 Re: Precision of calculated numeric fields
Previous Message Mihai Gheorghiu 2000-06-06 19:02:19 Dump