Re: BUG #9652: inet types don't support min/max - Mailing list pgsql-bugs

From Haribabu Kommi
Subject Re: BUG #9652: inet types don't support min/max
Date
Msg-id CAJrrPGdeZpfTPR6EkGgM6A4bUG7BVVToXsMgqJ6rg7R1JRUPVg@mail.gmail.com
Whole thread Raw
In response to BUG #9652: inet types don't support min/max  (darius@dons.net.au)
Responses Re: BUG #9652: inet types don't support min/max  (Keith Fiske <keith@omniti.com>)
List pgsql-bugs
On Fri, Mar 21, 2014 at 5:17 PM,  <darius@dons.net.au> wrote:
> The following bug has been logged on the website:
> reclog=> select * from foo;
>    bar
> ---------
>  1.2.3.4
> (1 row)
>
> reclog=> select min(bar) from foo;
> ERROR:  function min(inet) does not exist
> LINE 1: select min(bar) from foo;
>                ^
> HINT:  No function matches the given name and argument types. You might need
> to add explicit type casts.
>
> This is surprising to me since the inet type is ordered, hence min/max are
> possible.

In the code, some comparison logic for the inet datatypes already present.
With those I thought it is easy to support the min and max aggregates also.
So I modified the code to support the aggregate functions of min and
max by using
the already existing inet comparison logic. Is there anything I am missing?

postgres=# create table tbl(f inet);
CREATE TABLE
postgres=# insert into tbl values('1.2.3.5');
INSERT 0 1
postgres=# insert into tbl values('1.2.3.4');
INSERT 0 1
postgres=# select min(f) from tbl;
   min
---------
 1.2.3.4
(1 row)

postgres=# select max(f) from tbl;
   max
---------
 1.2.3.5
(1 row)

Patch is attached.
This is the first time I am touching this area so please let me know
your suggestions.

Regards,
Hari Babu
Fujitsu Australia

Attachment

pgsql-bugs by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: PQclientEncoding() returns -1, resulting in possible assertion failure in psql
Next
From: amir baron
Date:
Subject: Bug in PostgreSQL locking mechanism or misunderstanding of the mechanism