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

From Tom Lane
Subject Re: getting inet out of char?
Date
Msg-id 2017.960351623@sss.pgh.pa.us
Whole thread Raw
In response to getting inet out of char?  (Andrew Sullivan <sullivana@bpl.on.ca>)
Responses Re: getting inet out of char?  (Andrew Sullivan <sullivana@bpl.on.ca>)
List pgsql-general
Andrew Sullivan <sullivana@bpl.on.ca> writes:
> 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.

Seems like the cleanest answer would be to teach PHP about inet data
type (not to mention other extension types).  I've got no idea what
that would take, but ...

> 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.)

You could create a C-coded function to do the transformation, or you
could replace the rule with a trigger coded in pltcl or plperl.  I
believe both the pltcl and plperl languages are basically datatype-
ignorant --- as long as the textual output from one data value looks
like the format the input routine for another type is expecting,
it'll work.  SQL rules and plpgsql functions are far more anal-
retentive about type checking.  Sometimes that's good, sometimes not
so good.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Composite Types
Next
From: Eugene Karpachov
Date:
Subject: Re: Releases: 7.0.1, 7.0.2