Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6c40f83

Browse files
committed
Add min and max aggregates for inet/cidr data types.
Haribabu Kommi, reviewed by Muhammad Asif Naeem
1 parentec544a6 commit6c40f83

File tree

8 files changed

+59
-3
lines changed

8 files changed

+59
-3
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12192,7 +12192,8 @@ NULL baz</literallayout>(3 rows)</entry>
1219212192
</indexterm>
1219312193
<function>max(<replaceable class="parameter">expression</replaceable>)</function>
1219412194
</entry>
12195-
<entry>any array, numeric, string, or date/time type</entry>
12195+
<entry>any numeric, string, date/time, network, or enum type,
12196+
or arrays of these types</entry>
1219612197
<entry>same as argument type</entry>
1219712198
<entry>
1219812199
maximum value of <replaceable
@@ -12208,7 +12209,8 @@ NULL baz</literallayout>(3 rows)</entry>
1220812209
</indexterm>
1220912210
<function>min(<replaceable class="parameter">expression</replaceable>)</function>
1221012211
</entry>
12211-
<entry>any array, numeric, string, or date/time type</entry>
12212+
<entry>any numeric, string, date/time, network, or enum type,
12213+
or arrays of these types</entry>
1221212214
<entry>same as argument type</entry>
1221312215
<entry>
1221412216
minimum value of <replaceable

‎src/backend/utils/adt/network.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,33 @@ network_ne(PG_FUNCTION_ARGS)
471471
PG_RETURN_BOOL(network_cmp_internal(a1,a2)!=0);
472472
}
473473

474+
/*
475+
* MIN/MAX support functions.
476+
*/
477+
Datum
478+
network_smaller(PG_FUNCTION_ARGS)
479+
{
480+
inet*a1=PG_GETARG_INET_PP(0);
481+
inet*a2=PG_GETARG_INET_PP(1);
482+
483+
if (network_cmp_internal(a1,a2)<0)
484+
PG_RETURN_INET_P(a1);
485+
else
486+
PG_RETURN_INET_P(a2);
487+
}
488+
489+
Datum
490+
network_larger(PG_FUNCTION_ARGS)
491+
{
492+
inet*a1=PG_GETARG_INET_PP(0);
493+
inet*a2=PG_GETARG_INET_PP(1);
494+
495+
if (network_cmp_internal(a1,a2)>0)
496+
PG_RETURN_INET_P(a1);
497+
else
498+
PG_RETURN_INET_P(a2);
499+
}
500+
474501
/*
475502
* Support function for hash indexes on inet/cidr.
476503
*/

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO201408162
56+
#defineCATALOG_VERSION_NO201408281
5757

5858
#endif

‎src/include/catalog/pg_aggregate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ DATA(insert ( 2050n 0 array_larger----f f 10732277000_nu
164164
DATA(insert (2244n0bpchar_larger----ff10601042000_null__null_ ));
165165
DATA(insert (2797n0tidlarger----ff280027000_null__null_ ));
166166
DATA(insert (3526n0enum_larger----ff35193500000_null__null_ ));
167+
DATA(insert (3564n0network_larger----ff1205869000_null__null_ ));
167168

168169
/* min */
169170
DATA(insert (2131n0int8smaller----ff41220000_null__null_ ));
@@ -186,6 +187,7 @@ DATA(insert ( 2051n 0 array_smaller----f f 10722277000_n
186187
DATA(insert (2245n0bpchar_smaller----ff10581042000_null__null_ ));
187188
DATA(insert (2798n0tidsmaller----ff279927000_null__null_ ));
188189
DATA(insert (3527n0enum_smaller----ff35183500000_null__null_ ));
190+
DATA(insert (3565n0network_smaller----ff1203869000_null__null_ ));
189191

190192
/* count */
191193
DATA(insert (2147n0int8inc_any-int8inc_anyint8dec_any-ff0200200"0""0" ));

‎src/include/catalog/pg_proc.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,6 +2122,10 @@ DATA(insert OID = 922 ( network_lePGNSP PGUID 12 1 0 0 0 f f f t t f i 2 0 1
21222122
DATA(insertOID=923 (network_gtPGNSPPGUID121000fffttfi2016"869 869"_null__null__null__null_network_gt_null__null__null_ ));
21232123
DATA(insertOID=924 (network_gePGNSPPGUID121000fffttfi2016"869 869"_null__null__null__null_network_ge_null__null__null_ ));
21242124
DATA(insertOID=925 (network_nePGNSPPGUID121000fffttfi2016"869 869"_null__null__null__null_network_ne_null__null__null_ ));
2125+
DATA(insertOID=3562 (network_largerPGNSPPGUID121000fffftfi20869"869 869"_null__null__null__null_network_larger_null__null__null_ ));
2126+
DESCR("larger of two");
2127+
DATA(insertOID=3563 (network_smallerPGNSPPGUID121000fffftfi20869"869 869"_null__null__null__null_network_smaller_null__null__null_ ));
2128+
DESCR("smaller of two");
21252129
DATA(insertOID=926 (network_cmpPGNSPPGUID121000fffftfi2023"869 869"_null__null__null__null_network_cmp_null__null__null_ ));
21262130
DESCR("less-equal-greater");
21272131
DATA(insertOID=927 (network_subPGNSPPGUID121000fffftfi2016"869 869"_null__null__null__null_network_sub_null__null__null_ ));
@@ -3163,6 +3167,8 @@ DATA(insert OID = 2244 ( maxPGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1042 "
31633167
DESCR("maximum value of all bpchar input values");
31643168
DATA(insertOID=2797 (maxPGNSPPGUID121000tfffffi1027"27"_null__null__null__null_aggregate_dummy_null__null__null_ ));
31653169
DESCR("maximum value of all tid input values");
3170+
DATA(insertOID=3564 (maxPGNSPPGUID121000tfffffi10869"869"_null__null__null__null_aggregate_dummy_null__null__null_ ));
3171+
DESCR("maximum value of all inet input values");
31663172

31673173
DATA(insertOID=2131 (minPGNSPPGUID121000tfffffi1020"20"_null__null__null__null_aggregate_dummy_null__null__null_ ));
31683174
DESCR("minimum value of all bigint input values");
@@ -3202,6 +3208,8 @@ DATA(insert OID = 2245 ( minPGNSP PGUID 12 1 0 0 0 t f f f f f i 1 0 1042 "
32023208
DESCR("minimum value of all bpchar input values");
32033209
DATA(insertOID=2798 (minPGNSPPGUID121000tfffffi1027"27"_null__null__null__null_aggregate_dummy_null__null__null_ ));
32043210
DESCR("minimum value of all tid input values");
3211+
DATA(insertOID=3565 (minPGNSPPGUID121000tfffffi10869"869"_null__null__null__null_aggregate_dummy_null__null__null_ ));
3212+
DESCR("minimum value of all inet input values");
32053213

32063214
/* count has two forms: count(any) and count(*) */
32073215
DATA(insertOID=2147 (countPGNSPPGUID121000tfffffi1020"2276"_null__null__null__null_aggregate_dummy_null__null__null_ ));

‎src/include/utils/builtins.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,8 @@ extern Datum network_eq(PG_FUNCTION_ARGS);
908908
externDatumnetwork_ge(PG_FUNCTION_ARGS);
909909
externDatumnetwork_gt(PG_FUNCTION_ARGS);
910910
externDatumnetwork_ne(PG_FUNCTION_ARGS);
911+
externDatumnetwork_smaller(PG_FUNCTION_ARGS);
912+
externDatumnetwork_larger(PG_FUNCTION_ARGS);
911913
externDatumhashinet(PG_FUNCTION_ARGS);
912914
externDatumnetwork_sub(PG_FUNCTION_ARGS);
913915
externDatumnetwork_subeq(PG_FUNCTION_ARGS);

‎src/test/regress/expected/inet.out

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,18 @@ SELECT '' AS ten, i, c,
204204
| ::4.3.2.1/24 | ::ffff:1.2.3.4/128 | t | t | f | f | f | t | f | f | t | t | t
205205
(17 rows)
206206

207+
SELECT max(i) AS max, min(i) AS min FROM INET_TBL;
208+
max | min
209+
-------------+-----------
210+
10:23::ffff | 9.1.2.3/8
211+
(1 row)
212+
213+
SELECT max(c) AS max, min(c) AS min FROM INET_TBL;
214+
max | min
215+
-----------------+------------
216+
10:23::8000/113 | 10.0.0.0/8
217+
(1 row)
218+
207219
-- check the conversion to/from text and set_netmask
208220
SELECT '' AS ten, set_masklen(inet(text(i)), 24) FROM INET_TBL;
209221
ten | set_masklen

‎src/test/regress/sql/inet.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ SELECT '' AS ten, i, c,
5656
i && cAS ovr
5757
FROM INET_TBL;
5858

59+
SELECTmax(i)AS max,min(i)AS minFROM INET_TBL;
60+
SELECTmax(c)AS max,min(c)AS minFROM INET_TBL;
61+
5962
-- check the conversion to/from text and set_netmask
6063
SELECT''AS ten, set_masklen(inet(text(i)),24)FROM INET_TBL;
6164

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp