getting inet out of char? - Mailing list pgsql-general

From Andrew Sullivan
Subject getting inet out of char?
Date
Msg-id 20000606163824.F25986@bpl.on.ca
Whole thread Raw
Responses Re: getting inet out of char?  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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@bpl.on.ca>                        Burlington Public Library
+1 905 639 3611 x158                                   2331 New Street
                                   Burlington, Ontario, Canada L7R 1J4

pgsql-general by date:

Previous
From: Mihai Gheorghiu
Date:
Subject: Dump
Next
From: Tom Lane
Date:
Subject: Re: Precision of calculated numeric fields