Re: inet types and LIKE doesn't work as expected

From: Allan Engelhardt <allane(at)cybaea(dot)com>
To: Phil Mayers <p(dot)obfuscate(dot)mayers(at)ic(dot)ac(dot)uk>
Subject: Re: inet types and LIKE doesn't work as expected
Date: 2001-09-20 14:47:36
Message-ID: 3BAA0188.7346384E@cybaea.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Phil Mayers wrote:

> Try this:
>
> hdbdev=> create table ips ( ip inet, ip_txt varchar(15) );
> hdbdev=> insert into ips (ip,ip_txt) values ('192.168.1.1','192.168.1.1');
> hdbdev=> select * from ips where ip like '192.168.1.1';
> ip | ip_txt
> ----+--------
> (0 rows)
>
> hdbdev=> select * from ips where ip_txt like '192.168.1.1';
> ip | ip_txt
> -------------+-------------
> 192.168.1.1 | 192.168.1.1
> (1 row)
>
> That seems inconsistent?

The default text conversion for the inet type includes a mask:

test=# select text(ip) from ips;
text
----------------
192.168.1.1/32
(1 row)

so

select * from ips where ip like '192.168.1.1%';

works as expected.

The joys of semanically rich data types :-)

Hope this helps a little.

Allan.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Justin Clift 2001-09-20 16:23:03 Re: Performance question (stripped down the problem)
Previous Message Christof Petig 2001-09-20 14:38:09 Re: anoncvs troubles (was Re: CVS vs anoncvs)