On Mon, Jul 7, 2014 at 6:59 PM, Asif Naeem <[email protected]> wrote:
> Hi Haribabu,
>
> Thank you for sharing the patch. I have spent some time to review the
> changes. Overall patch looks good to me, make check and manual testing seems
> run fine with it. There seems no related doc/sgml changes ?. Patch added
> network_smaller() and network_greater() functions but in PG source code,
> general practice seems to be to use “smaller" and “larger” as related
> function name postfix e.g. timestamp_smaller()/timestamp_larger(),
> interval_smaller/interval_larger(), cashsmaller()/cashlarger() etc. Thanks.
Thanks for reviewing the patch.
I corrected the function names as smaller and larger.
and also added documentation changes.
Updated patch attached in the mail.
Regards,
Hari Babu
Fujitsu Australia
*** a/doc/src/sgml/func.sgml
--- b/doc/src/sgml/func.sgml
***************
*** 8647,8652 **** CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple
--- 8647,8676 ----
<row>
<entry>
<indexterm>
+ <primary>max</primary>
+ </indexterm>
+ <literal><function>max(<type>inet</type>, <type>inet</type>)</function></literal>
+ </entry>
+ <entry><type>inet</type></entry>
+ <entry>larger of two inet types</entry>
+ <entry><literal>max('192.168.1.5', '192.168.1.4')</literal></entry>
+ <entry><literal>192.168.1.5</literal></entry>
+ </row>
+ <row>
+ <entry>
+ <indexterm>
+ <primary>min</primary>
+ </indexterm>
+ <literal><function>min(<type>inet</type>, <type>inet</type>)</function></literal>
+ </entry>
+ <entry><type>inet</type></entry>
+ <entry>smaller of two inet types</entry>
+ <entry><literal>min('192.168.1.5', '192.168.1.4')</literal></entry>
+ <entry><literal>192.168.1.4</literal></entry>
+ </row>
+ <row>
+ <entry>
+ <indexterm>
<primary>netmask</primary>
</indexterm>
<literal><function>netmask(<type>inet</type>)</function></literal>
*** a/src/backend/utils/adt/network.c
--- b/src/backend/utils/adt/network.c
***************
*** 471,476 **** network_ne(PG_FUNCTION_ARGS)
--- 471,499 ----
PG_RETURN_BOOL(network_cmp_internal(a1, a2) != 0);
}
+ Datum
+ network_smaller(PG_FUNCTION_ARGS)
+ {
+ inet *a1 = PG_GETARG_INET_PP(0);
+ inet *a2 = PG_GETARG_INET_PP(1);
+
+ if (network_cmp_internal(a1, a2) < 0)
+ PG_RETURN_INET_P(a1);
+ else
+ PG_RETURN_INET_P(a2);
+ }
+
+ Datum
+ network_larger(PG_FUNCTION_ARGS)
+ {
+ inet *a1 = PG_GETARG_INET_PP(0);
+ inet *a2 = PG_GETARG_INET_PP(1);
+
+ if (network_cmp_internal(a1, a2) > 0)
+ PG_RETURN_INET_P(a1);
+ else
+ PG_RETURN_INET_P(a2);
+ }
/*
* Support function for hash indexes on inet/cidr.
*/
*** a/src/include/catalog/pg_aggregate.h
--- b/src/include/catalog/pg_aggregate.h
***************
*** 164,169 **** DATA(insert ( 2050 n 0 array_larger - - - - f f 1073 2277 0 0 0 _nu
--- 164,170 ----
DATA(insert ( 2244 n 0 bpchar_larger - - - - f f 1060 1042 0 0 0 _null_ _null_ ));
DATA(insert ( 2797 n 0 tidlarger - - - - f f 2800 27 0 0 0 _null_ _null_ ));
DATA(insert ( 3526 n 0 enum_larger - - - - f f 3519 3500 0 0 0 _null_ _null_ ));
+ DATA(insert ( 3255 n 0 network_larger - - - - f f 1205 869 0 0 0 _null_ _null_ ));
/* min */
DATA(insert ( 2131 n 0 int8smaller - - - - f f 412 20 0 0 0 _null_ _null_ ));
***************
*** 186,191 **** DATA(insert ( 2051 n 0 array_smaller - - - - f f 1072 2277 0 0 0 _n
--- 187,193 ----
DATA(insert ( 2245 n 0 bpchar_smaller - - - - f f 1058 1042 0 0 0 _null_ _null_ ));
DATA(insert ( 2798 n 0 tidsmaller - - - - f f 2799 27 0 0 0 _null_ _null_ ));
DATA(insert ( 3527 n 0 enum_smaller - - - - f f 3518 3500 0 0 0 _null_ _null_ ));
+ DATA(insert ( 3256 n 0 network_smaller - - - - f f 1203 869 0 0 0 _null_ _null_ ));
/* count */
DATA(insert ( 2147 n 0 int8inc_any - int8inc_any int8dec_any - f f 0 20 0 20 0 "0" "0" ));
*** a/src/include/catalog/pg_proc.h
--- b/src/include/catalog/pg_proc.h
***************
*** 2120,2125 **** DATA(insert OID = 922 ( network_le PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 1
--- 2120,2129 ----
DATA(insert OID = 923 ( network_gt PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_gt _null_ _null_ _null_ ));
DATA(insert OID = 924 ( network_ge PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_ge _null_ _null_ _null_ ));
DATA(insert OID = 925 ( network_ne PGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_ne _null_ _null_ _null_ ));
+ DATA(insert OID = 3257 ( network_larger PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 869 "869 869" _null_ _null_ _null_ _null_ network_larger _null_ _null_ _null_ ));
+ DESCR("larger of two network types");
+ DATA(insert OID = 3258 ( network_smaller PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 869 "869 869" _null_ _null_ _null_ _null_ network_smaller _null_ _null_ _null_ ));
+ DESCR("smaller of two network types");
DATA(insert OID = 926 ( network_cmp PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 23 "869 869" _null_ _null_ _null_ _null_ network_cmp _null_ _null_ _null_ ));
DESCR("less-equal-greater");
DATA(insert OID = 927 ( network_sub PGNSP PGUID 12 1 0 0 0 f f f f t f i 2 0 16 "869 869" _null_ _null_ _null_ _null_ network_sub _null_ _null_ _null_ ));
***************
*** 3161,3166 **** DATA(insert OID = 2244 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1042 "
--- 3165,3172 ----
DESCR("maximum value of all bpchar input values");
DATA(insert OID = 2797 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 27 "27" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ ));
DESCR("maximum value of all tid input values");
+ DATA(insert OID = 3255 ( max PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 869 "869" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ ));
+ DESCR("maximum value of all inet input values");
DATA(insert OID = 2131 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 20 "20" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ ));
DESCR("minimum value of all bigint input values");
***************
*** 3200,3205 **** DATA(insert OID = 2245 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1042 "
--- 3206,3213 ----
DESCR("minimum value of all bpchar input values");
DATA(insert OID = 2798 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 27 "27" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ ));
DESCR("minimum value of all tid input values");
+ DATA(insert OID = 3256 ( min PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 869 "869" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ ));
+ DESCR("minimum value of all inet input values");
/* count has two forms: count(any) and count(*) */
DATA(insert OID = 2147 ( count PGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 20 "2276" _null_ _null_ _null_ _null_ aggregate_dummy _null_ _null_ _null_ ));
*** a/src/include/utils/builtins.h
--- b/src/include/utils/builtins.h
***************
*** 907,912 **** extern Datum network_eq(PG_FUNCTION_ARGS);
--- 907,914 ----
extern Datum network_ge(PG_FUNCTION_ARGS);
extern Datum network_gt(PG_FUNCTION_ARGS);
extern Datum network_ne(PG_FUNCTION_ARGS);
+ extern Datum network_smaller(PG_FUNCTION_ARGS);
+ extern Datum network_larger(PG_FUNCTION_ARGS);
extern Datum hashinet(PG_FUNCTION_ARGS);
extern Datum network_sub(PG_FUNCTION_ARGS);
extern Datum network_subeq(PG_FUNCTION_ARGS);
*** a/src/test/regress/expected/inet.out
--- b/src/test/regress/expected/inet.out
***************
*** 204,209 **** SELECT '' AS ten, i, c,
--- 204,215 ----
| ::4.3.2.1/24 | ::ffff:1.2.3.4/128 | t | t | f | f | f | t | f | f | t | t | t
(17 rows)
+ SELECT max(i) as max, min(i) as min FROM INET_TBL;
+ max | min
+ -------------+-----------
+ 10:23::ffff | 9.1.2.3/8
+ (1 row)
+
-- check the conversion to/from text and set_netmask
SELECT '' AS ten, set_masklen(inet(text(i)), 24) FROM INET_TBL;
ten | set_masklen
*** a/src/test/regress/sql/inet.sql
--- b/src/test/regress/sql/inet.sql
***************
*** 56,61 **** SELECT '' AS ten, i, c,
--- 56,63 ----
i && c AS ovr
FROM INET_TBL;
+ SELECT max(i) as max, min(i) as min FROM INET_TBL;
+
-- check the conversion to/from text and set_netmask
SELECT '' AS ten, set_masklen(inet(text(i)), 24) FROM INET_TBL;
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers