Re: getting inet out of char?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: getting inet out of char?
Дата
Msg-id 2017.960351623@sss.pgh.pa.us
обсуждение исходный текст
Ответ на getting inet out of char?  (Andrew Sullivan <sullivana@bpl.on.ca>)
Ответы Re: getting inet out of char?
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Composite Types
Следующее
От: Eugene Karpachov
Дата:
Сообщение: Re: Releases: 7.0.1, 7.0.2