Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
cc53a1e7
Commit
cc53a1e7
authored
Jan 19, 2012
by
Robert Haas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add bitwise AND, OR, and NOT operators for macaddr data type.
Brendan Jurd, reviewed by Fujii Masao
parent
4f42b546
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
122 additions
and
2 deletions
+122
-2
doc/src/sgml/func.sgml
doc/src/sgml/func.sgml
+3
-1
src/backend/utils/adt/mac.c
src/backend/utils/adt/mac.c
+53
-0
src/include/catalog/catversion.h
src/include/catalog/catversion.h
+1
-1
src/include/catalog/pg_operator.h
src/include/catalog/pg_operator.h
+7
-0
src/include/catalog/pg_proc.h
src/include/catalog/pg_proc.h
+3
-0
src/include/utils/builtins.h
src/include/utils/builtins.h
+3
-0
src/test/regress/expected/macaddr.out
src/test/regress/expected/macaddr.out
+48
-0
src/test/regress/sql/macaddr.sql
src/test/regress/sql/macaddr.sql
+4
-0
No files found.
doc/src/sgml/func.sgml
View file @
cc53a1e7
...
@@ -8300,7 +8300,9 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple
...
@@ -8300,7 +8300,9 @@ CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple
<para>
<para>
The
<type>
macaddr
</type>
type also supports the standard relational
The
<type>
macaddr
</type>
type also supports the standard relational
operators (
<literal>
>
</literal>
,
<literal>
<
=
</literal>
, etc.) for
operators (
<literal>
>
</literal>
,
<literal>
<
=
</literal>
, etc.) for
lexicographical ordering.
lexicographical ordering, and the bitwise arithmetic operators
(
<literal>
~
</literal>
,
<literal>
&
</literal>
and
<literal>
|
</literal>
)
for NOT, AND and OR.
</para>
</para>
</sect1>
</sect1>
...
...
src/backend/utils/adt/mac.c
View file @
cc53a1e7
...
@@ -241,6 +241,59 @@ hashmacaddr(PG_FUNCTION_ARGS)
...
@@ -241,6 +241,59 @@ hashmacaddr(PG_FUNCTION_ARGS)
return
hash_any
((
unsigned
char
*
)
key
,
sizeof
(
macaddr
));
return
hash_any
((
unsigned
char
*
)
key
,
sizeof
(
macaddr
));
}
}
/*
* Arithmetic functions: bitwise NOT, AND, OR.
*/
Datum
macaddr_not
(
PG_FUNCTION_ARGS
)
{
macaddr
*
addr
=
PG_GETARG_MACADDR_P
(
0
);
macaddr
*
result
;
result
=
(
macaddr
*
)
palloc
(
sizeof
(
macaddr
));
result
->
a
=
~
addr
->
a
;
result
->
b
=
~
addr
->
b
;
result
->
c
=
~
addr
->
c
;
result
->
d
=
~
addr
->
d
;
result
->
e
=
~
addr
->
e
;
result
->
f
=
~
addr
->
f
;
PG_RETURN_MACADDR_P
(
result
);
}
Datum
macaddr_and
(
PG_FUNCTION_ARGS
)
{
macaddr
*
addr1
=
PG_GETARG_MACADDR_P
(
0
);
macaddr
*
addr2
=
PG_GETARG_MACADDR_P
(
1
);
macaddr
*
result
;
result
=
(
macaddr
*
)
palloc
(
sizeof
(
macaddr
));
result
->
a
=
addr1
->
a
&
addr2
->
a
;
result
->
b
=
addr1
->
b
&
addr2
->
b
;
result
->
c
=
addr1
->
c
&
addr2
->
c
;
result
->
d
=
addr1
->
d
&
addr2
->
d
;
result
->
e
=
addr1
->
e
&
addr2
->
e
;
result
->
f
=
addr1
->
f
&
addr2
->
f
;
PG_RETURN_MACADDR_P
(
result
);
}
Datum
macaddr_or
(
PG_FUNCTION_ARGS
)
{
macaddr
*
addr1
=
PG_GETARG_MACADDR_P
(
0
);
macaddr
*
addr2
=
PG_GETARG_MACADDR_P
(
1
);
macaddr
*
result
;
result
=
(
macaddr
*
)
palloc
(
sizeof
(
macaddr
));
result
->
a
=
addr1
->
a
|
addr2
->
a
;
result
->
b
=
addr1
->
b
|
addr2
->
b
;
result
->
c
=
addr1
->
c
|
addr2
->
c
;
result
->
d
=
addr1
->
d
|
addr2
->
d
;
result
->
e
=
addr1
->
e
|
addr2
->
e
;
result
->
f
=
addr1
->
f
|
addr2
->
f
;
PG_RETURN_MACADDR_P
(
result
);
}
/*
/*
* Truncation function to allow comparing mac manufacturers.
* Truncation function to allow comparing mac manufacturers.
* From suggestion by Alex Pilosov <alex@pilosoft.com>
* From suggestion by Alex Pilosov <alex@pilosoft.com>
...
...
src/include/catalog/catversion.h
View file @
cc53a1e7
...
@@ -53,6 +53,6 @@
...
@@ -53,6 +53,6 @@
*/
*/
/* yyyymmddN */
/* yyyymmddN */
#define CATALOG_VERSION_NO 20120119
1
#define CATALOG_VERSION_NO 20120119
2
#endif
#endif
src/include/catalog/pg_operator.h
View file @
cc53a1e7
...
@@ -1116,6 +1116,13 @@ DESCR("greater than");
...
@@ -1116,6 +1116,13 @@ DESCR("greater than");
DATA
(
insert
OID
=
1225
(
">="
PGNSP
PGUID
b
f
f
829
829
16
1223
1222
macaddr_ge
scalargtsel
scalargtjoinsel
));
DATA
(
insert
OID
=
1225
(
">="
PGNSP
PGUID
b
f
f
829
829
16
1223
1222
macaddr_ge
scalargtsel
scalargtjoinsel
));
DESCR
(
"greater than or equal"
);
DESCR
(
"greater than or equal"
);
DATA
(
insert
OID
=
3147
(
"~"
PGNSP
PGUID
l
f
f
0
829
829
0
0
macaddr_not
-
-
));
DESCR
(
"bitwise not"
);
DATA
(
insert
OID
=
3148
(
"&"
PGNSP
PGUID
b
f
f
829
829
829
0
0
macaddr_and
-
-
));
DESCR
(
"bitwise and"
);
DATA
(
insert
OID
=
3149
(
"|"
PGNSP
PGUID
b
f
f
829
829
829
0
0
macaddr_or
-
-
));
DESCR
(
"bitwise or"
);
/* INET type (these also support CIDR via implicit cast) */
/* INET type (these also support CIDR via implicit cast) */
DATA
(
insert
OID
=
1201
(
"="
PGNSP
PGUID
b
t
t
869
869
16
1201
1202
network_eq
eqsel
eqjoinsel
));
DATA
(
insert
OID
=
1201
(
"="
PGNSP
PGUID
b
t
t
869
869
16
1201
1202
network_eq
eqsel
eqjoinsel
));
DESCR
(
"equal"
);
DESCR
(
"equal"
);
...
...
src/include/catalog/pg_proc.h
View file @
cc53a1e7
...
@@ -2039,6 +2039,9 @@ DATA(insert OID = 834 ( macaddr_ge PGNSP PGUID 12 1 0 0 0 f f f t f i 2 0 16
...
@@ -2039,6 +2039,9 @@ DATA(insert OID = 834 ( macaddr_ge PGNSP PGUID 12 1 0 0 0 f f f t f i 2 0 16
DATA
(
insert
OID
=
835
(
macaddr_ne
PGNSP
PGUID
12
1
0
0
0
f
f
f
t
f
i
2
0
16
"829 829"
_null_
_null_
_null_
_null_
macaddr_ne
_null_
_null_
_null_
));
DATA
(
insert
OID
=
835
(
macaddr_ne
PGNSP
PGUID
12
1
0
0
0
f
f
f
t
f
i
2
0
16
"829 829"
_null_
_null_
_null_
_null_
macaddr_ne
_null_
_null_
_null_
));
DATA
(
insert
OID
=
836
(
macaddr_cmp
PGNSP
PGUID
12
1
0
0
0
f
f
f
t
f
i
2
0
23
"829 829"
_null_
_null_
_null_
_null_
macaddr_cmp
_null_
_null_
_null_
));
DATA
(
insert
OID
=
836
(
macaddr_cmp
PGNSP
PGUID
12
1
0
0
0
f
f
f
t
f
i
2
0
23
"829 829"
_null_
_null_
_null_
_null_
macaddr_cmp
_null_
_null_
_null_
));
DESCR
(
"less-equal-greater"
);
DESCR
(
"less-equal-greater"
);
DATA
(
insert
OID
=
3144
(
macaddr_not
PGNSP
PGUID
12
1
0
0
0
f
f
f
t
f
i
1
0
829
"829"
_null_
_null_
_null_
_null_
macaddr_not
_null_
_null_
_null_
));
DATA
(
insert
OID
=
3145
(
macaddr_and
PGNSP
PGUID
12
1
0
0
0
f
f
f
t
f
i
2
0
829
"829 829"
_null_
_null_
_null_
_null_
macaddr_and
_null_
_null_
_null_
));
DATA
(
insert
OID
=
3146
(
macaddr_or
PGNSP
PGUID
12
1
0
0
0
f
f
f
t
f
i
2
0
829
"829 829"
_null_
_null_
_null_
_null_
macaddr_or
_null_
_null_
_null_
));
/* for inet type support */
/* for inet type support */
DATA
(
insert
OID
=
910
(
inet_in
PGNSP
PGUID
12
1
0
0
0
f
f
f
t
f
i
1
0
869
"2275"
_null_
_null_
_null_
_null_
inet_in
_null_
_null_
_null_
));
DATA
(
insert
OID
=
910
(
inet_in
PGNSP
PGUID
12
1
0
0
0
f
f
f
t
f
i
1
0
869
"2275"
_null_
_null_
_null_
_null_
inet_in
_null_
_null_
_null_
));
...
...
src/include/utils/builtins.h
View file @
cc53a1e7
...
@@ -900,6 +900,9 @@ extern Datum macaddr_eq(PG_FUNCTION_ARGS);
...
@@ -900,6 +900,9 @@ extern Datum macaddr_eq(PG_FUNCTION_ARGS);
extern
Datum
macaddr_ge
(
PG_FUNCTION_ARGS
);
extern
Datum
macaddr_ge
(
PG_FUNCTION_ARGS
);
extern
Datum
macaddr_gt
(
PG_FUNCTION_ARGS
);
extern
Datum
macaddr_gt
(
PG_FUNCTION_ARGS
);
extern
Datum
macaddr_ne
(
PG_FUNCTION_ARGS
);
extern
Datum
macaddr_ne
(
PG_FUNCTION_ARGS
);
extern
Datum
macaddr_not
(
PG_FUNCTION_ARGS
);
extern
Datum
macaddr_and
(
PG_FUNCTION_ARGS
);
extern
Datum
macaddr_or
(
PG_FUNCTION_ARGS
);
extern
Datum
macaddr_trunc
(
PG_FUNCTION_ARGS
);
extern
Datum
macaddr_trunc
(
PG_FUNCTION_ARGS
);
extern
Datum
hashmacaddr
(
PG_FUNCTION_ARGS
);
extern
Datum
hashmacaddr
(
PG_FUNCTION_ARGS
);
...
...
src/test/regress/expected/macaddr.out
View file @
cc53a1e7
...
@@ -103,4 +103,52 @@ SELECT b <> '08:00:2b:01:02:03' FROM macaddr_data WHERE a = 1; -- false
...
@@ -103,4 +103,52 @@ SELECT b <> '08:00:2b:01:02:03' FROM macaddr_data WHERE a = 1; -- false
f
f
(1 row)
(1 row)
SELECT ~b FROM macaddr_data;
?column?
-------------------
f7:ff:d4:fe:fd:fc
f7:ff:d4:fe:fd:fc
f7:ff:d4:fe:fd:fc
f7:ff:d4:fe:fd:fc
f7:ff:d4:fe:fd:fc
f7:ff:d4:fe:fd:fc
f7:ff:d4:fe:fd:fb
f7:ff:d4:fe:fd:fd
f7:ff:d5:fe:fd:fc
f7:ff:d3:fe:fd:fc
f7:ff:d5:fe:fd:fb
(11 rows)
SELECT b & '00:00:00:ff:ff:ff' FROM macaddr_data;
?column?
-------------------
00:00:00:01:02:03
00:00:00:01:02:03
00:00:00:01:02:03
00:00:00:01:02:03
00:00:00:01:02:03
00:00:00:01:02:03
00:00:00:01:02:04
00:00:00:01:02:02
00:00:00:01:02:03
00:00:00:01:02:03
00:00:00:01:02:04
(11 rows)
SELECT b | '01:02:03:04:05:06' FROM macaddr_data;
?column?
-------------------
09:02:2b:05:07:07
09:02:2b:05:07:07
09:02:2b:05:07:07
09:02:2b:05:07:07
09:02:2b:05:07:07
09:02:2b:05:07:07
09:02:2b:05:07:06
09:02:2b:05:07:06
09:02:2b:05:07:07
09:02:2f:05:07:07
09:02:2b:05:07:06
(11 rows)
DROP TABLE macaddr_data;
DROP TABLE macaddr_data;
src/test/regress/sql/macaddr.sql
View file @
cc53a1e7
...
@@ -35,4 +35,8 @@ SELECT b = '08:00:2b:01:02:03' FROM macaddr_data WHERE a = 1; -- true
...
@@ -35,4 +35,8 @@ SELECT b = '08:00:2b:01:02:03' FROM macaddr_data WHERE a = 1; -- true
SELECT
b
<>
'08:00:2b:01:02:04'
FROM
macaddr_data
WHERE
a
=
1
;
-- true
SELECT
b
<>
'08:00:2b:01:02:04'
FROM
macaddr_data
WHERE
a
=
1
;
-- true
SELECT
b
<>
'08:00:2b:01:02:03'
FROM
macaddr_data
WHERE
a
=
1
;
-- false
SELECT
b
<>
'08:00:2b:01:02:03'
FROM
macaddr_data
WHERE
a
=
1
;
-- false
SELECT
~
b
FROM
macaddr_data
;
SELECT
b
&
'00:00:00:ff:ff:ff'
FROM
macaddr_data
;
SELECT
b
|
'01:02:03:04:05:06'
FROM
macaddr_data
;
DROP
TABLE
macaddr_data
;
DROP
TABLE
macaddr_data
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment