Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement #3130 Update docs on new INET functions #4661

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions docs/extensions/inet.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,102 @@ SELECT cidr, host(cidr) FROM tbl;
| 127.0.0.1 | 127.0.0.1 |
| 2001:db8:3c4d:15::1a2f:1a2b/96 | 2001:db8:3c4d:15::1a2f:1a2b |


## `netmask` Function

Computes the network mask for the address's network.

```sql
CREATE TABLE tbl (cidr INET);
INSERT INTO tbl VALUES
('192.168.1.5/24'),
('127.0.0.1'),
('2001:db8:3c4d:15::1a2f:1a2b/96');
SELECT cidr, netmask(cidr) FROM tbl;
```

| cidr | netmask(cidr) |
|--------------------------------|------------------------------------|
| 192.168.1.5/24 | 255.255.255.0/24 |
| 127.0.0.1 | 255.255.255.255 |
| 2001:db8:3c4d:15::1a2f:1a2b/96 | ffff:ffff:ffff:ffff:ffff:ffff::/96 |

## `network` Function

Returns the network part of the address, zeroing out whatever is to the right of the netmask.

```sql
CREATE TABLE tbl (cidr INET);
INSERT INTO tbl VALUES
('192.168.1.5/24'),
('127.0.0.1'),
('2001:db8:3c4d:15::1a2f:1a2b/96');
SELECT cidr, network(cidr) FROM tbl;
```

| cidr | network(cidr) |
|--------------------------------|------------------------------------|
| 192.168.1.5/24 | 192.168.1.0/24 |
| 127.0.0.1 | 255.255.255.255 |
| 2001:db8:3c4d:15::1a2f:1a2b/96 | ffff:ffff:ffff:ffff:ffff:ffff::/96 |

## `broadcast` Function

Computes the broadcast address for the address's network.

```sql
CREATE TABLE tbl (cidr INET);
INSERT INTO tbl VALUES
('192.168.1.5/24'),
('127.0.0.1'),
('2001:db8:3c4d:15::1a2f:1a2b/96');
SELECT cidr, broadcast(cidr) FROM tbl;
```

| cidr | broadcast(cidr) |
|--------------------------------|------------------------------------|
| 192.168.1.5/24 | 192.168.1.0/24 |
| 127.0.0.1 | 127.0.0.1 |
| 2001:db8:3c4d:15::1a2f:1a2b/96 | 2001:db8:3c4d:15::/96 |

## `<<=` Predicate

Is subnet contained by or equal to subnet?

```sql
CREATE TABLE tbl (cidr INET);
INSERT INTO tbl VALUES
('192.168.1.0/24'),
('127.0.0.1'),
('2001:db8:3c4d:15::1a2f:1a2b/96');
SELECT cidr, INET '192.168.1.5/32' <<= cidr FROM tbl;
```

| cidr | (CAST('192.168.1.5/32' AS INET) <<= cidr) |
|--------------------------------|---------------------------------------------|
| 192.168.1.5/24 | true |
| 127.0.0.1 | false |
| 2001:db8:3c4d:15::1a2f:1a2b/96 | false |

## `>>=` Predicate

Does subnet contain or equal subnet?

```sql
CREATE TABLE tbl (cidr INET);
INSERT INTO tbl VALUES
('192.168.1.0/24'),
('127.0.0.1'),
('2001:db8:3c4d:15::1a2f:1a2b/96');
SELECT cidr, INET '192.168.0.0/16' >>= cidr FROM tbl;
```

| cidr | (CAST('192.168.0.0/16' AS INET) >>= cidr) |
|--------------------------------|---------------------------------------------|
| 192.168.1.5/24 | true |
| 127.0.0.1 | false |
| 2001:db8:3c4d:15::1a2f:1a2b/96 | false |

## HTML Escape and Unescape Functions

```sql
Expand Down