Thread: casting TEXT to CIDR (or to INET) has to be possible

casting TEXT to CIDR (or to INET) has to be possible

From
Paul Vixie
Date:
============================================================================
                        POSTGRESQL BUG REPORT TEMPLATE
============================================================================


Your name        :    Paul Vixie
Your email address    :    paul@vix.com


System Configuration
---------------------
  Architecture (example: Intel Pentium)      :    Intel Dual Pentium

  Operating System (example: Linux 2.0.26 ELF)     :    Freebsd 4.3

  PostgreSQL version (example: PostgreSQL-7.1.1):   PostgreSQL-7.2devel

  Compiler used (example:  gcc 2.95.2)        :    gcc version 2.95.3


Please enter a FULL description of your problem:
------------------------------------------------

I know there's code in the server to convert presentation-format INET or CIDR
into internal format.  To get the effect of C's "inet_netof()" I need to be
able to do this conversion from TEXT rather than from interpreter literals.


Please describe a way to repeat the problem.   Please try to provide a
concise reproducible example, if at all possible:
----------------------------------------------------------------------

lartomatic=# select (host(relay)||'/18')::cidr from spam limit 5;
ERROR:  Cannot cast type 'text' to 'cidr'
lartomatic=# select (host(relay)||'/18')::inet from spam limit 5;
ERROR:  Cannot cast type 'text' to 'inet'



If you know how this problem might be fixed, list the solution below:
---------------------------------------------------------------------

Nope, this is beyond my abilities.

Re: casting TEXT to CIDR (or to INET) has to be possible

From
Tom Lane
Date:
Paul Vixie <paul@vix.com> writes:
> lartomatic=# select (host(relay)||'/18')::cidr from spam limit 5;
> ERROR:  Cannot cast type 'text' to 'cidr'
> lartomatic=# select (host(relay)||'/18')::inet from spam limit 5;
> ERROR:  Cannot cast type 'text' to 'inet'

Your wish is our command ;-).  It seems to work okay in 7.2 beta:

regression=# create table spam(relay inet);
CREATE
regression=# insert into spam values ('127.0.0.1');
INSERT 287658 1
regression=# select (host(relay)||'/18')::cidr from spam limit 5;
ERROR:  invalid CIDR value '127.0.0.1/18': has bits set to right of mask
regression=# select (host(relay)||'/18')::inet from spam limit 5;
     inet
--------------
 127.0.0.1/18
(1 row)

            regards, tom lane