Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion content/compatibility/sql_features.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ the [system table compatibility](../system_table) page.
| circle | No | |
| date | Yes | [Date Documentation](/docs/references/datatypes/date) |
| double precision | Yes | [Double Documentation](/docs/references/datatypes/float) |
| inet | No | |
| inet | Partial | [Inet Documentation](/docs/references/datatypes/inet) |
| integer | Yes | [Integer Documentation](/docs/references/datatypes/integer) |
| interval [ fields ] [ (p) ] | Yes | [Interval Documentation](/docs/references/datatypes/interval) |
| json | Yes | [JSON Documentation](/docs/references/datatypes/json) |
Expand Down
1 change: 1 addition & 0 deletions content/references/datatypes/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The complete list of supported data types in CedarDB is as follows:
* [`double precision`](float)
* [`enum`](enums)
* [`float`](float)
* [`inet`](inet)
* [`integer`](integer) (`int4`)
* [`interval`](interval)
* [`json`](json)
Expand Down
118 changes: 118 additions & 0 deletions content/references/datatypes/inet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
---
title: "Reference: Inet Type"
linkTitle: "Inet"
weight: 24
---

The `inet` type stores an IPv4 or IPv6 host address, optionally together with its subnet as a netmask length.

Check failure on line 7 in content/references/datatypes/inet.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'netmask'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'netmask'?", "location": {"path": "content/references/datatypes/inet.md", "range": {"start": {"line": 7, "column": 95}}}, "severity": "ERROR"}

Check failure on line 7 in content/references/datatypes/inet.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'subnet'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'subnet'?", "location": {"path": "content/references/datatypes/inet.md", "range": {"start": {"line": 7, "column": 83}}}, "severity": "ERROR"}
For example, `192.168.1.5/24` describes the host `192.168.1.5` in the subnet `192.168.1.0/24`.

Check failure on line 8 in content/references/datatypes/inet.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'subnet'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'subnet'?", "location": {"path": "content/references/datatypes/inet.md", "range": {"start": {"line": 8, "column": 71}}}, "severity": "ERROR"}

{{< callout type="info" >}}
CedarDB currently only supports basic `inet` functionality.
PostgreSQL's network operators, functions (for example, `<<`, `host()`, or `masklen()`), the `cidr` type, and

Check failure on line 12 in content/references/datatypes/inet.md

View workflow job for this annotation

GitHub Actions / markdownlint

Trailing spaces

content/references/datatypes/inet.md:12:110 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1] https://github.com/DavidAnson/markdownlint/blob/v0.40.0/doc/md009.md
non-standard prefix-only IPs (`10/24`) are not yet supported.

Check failure on line 13 in content/references/datatypes/inet.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'IPs'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'IPs'?", "location": {"path": "content/references/datatypes/inet.md", "range": {"start": {"line": 13, "column": 26}}}, "severity": "ERROR"}
{{< /callout >}}

## Usage Example

```sql
create table connections (
client inet,
ts timestamp
);
insert into connections values
('192.168.1.226/24', now()),
('10.1.2.3', now()),
('10:23::f1/64', now()),
('::1', now());
select client from connections order by client;
```

```text
client
------------------
10.1.2.3
192.168.1.226/24
::1
10:23::f1/64
(4 rows)
```

## Input

`inet` values are written as `address/bits`, where `address` is an IPv4 or IPv6 address and `bits` is the netmask.

Check failure on line 43 in content/references/datatypes/inet.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'netmask'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'netmask'?", "location": {"path": "content/references/datatypes/inet.md", "range": {"start": {"line": 43, "column": 107}}}, "severity": "ERROR"}
Omitting the `/bits` specifies a single host with a full netmask.

Check failure on line 44 in content/references/datatypes/inet.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'netmask'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'netmask'?", "location": {"path": "content/references/datatypes/inet.md", "range": {"start": {"line": 44, "column": 58}}}, "severity": "ERROR"}

```sql
-- IPv4
select inet '192.168.1.226/24';
select inet '192.168.1.226';
-- IPv6
select inet '10:23::f1/64';
select inet '0000:0000:0000:0000:0000:0000:0000:0001';
-- IPv6 with the last 32 bits in dotted IPv4 notation
select inet '::4.3.2.1/24';
```

## Output

CedarDB prints `inet` values in their normalized RFC 3493 form, and omits the netmask in the output for a single hosts.

Check failure on line 59 in content/references/datatypes/inet.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'netmask'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'netmask'?", "location": {"path": "content/references/datatypes/inet.md", "range": {"start": {"line": 59, "column": 79}}}, "severity": "ERROR"}
IPv6 addresses are printed in their shortest form, without leading zeros and with the longest run of zero groups
replaced by `::`:

```sql
select inet '10.1.2.3/32', inet '0000:0000:0000:0000:0000:0000:0000:0001/128', inet '8000:0000:0000:0000:0000:0000:0000:0000/1';
```

```text
inet | inet | inet
----------+------+---------
10.1.2.3 | ::1 | 8000::/1
(1 row)
```

## Comparison and Sorting

`inet` values support the regular comparison operators:
IPv4 addresses sort before IPv6 addresses.
Within the same address family, values are first compared by their network part, then by their netmask length,

Check failure on line 78 in content/references/datatypes/inet.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'netmask'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'netmask'?", "location": {"path": "content/references/datatypes/inet.md", "range": {"start": {"line": 78, "column": 96}}}, "severity": "ERROR"}
and then by the full address.

```sql
select a from (values
('192.168.1.0/24'::inet),
('192.168.1.0/25'::inet),
('192.168.1.1/23'::inet),
('10:23::ffff'::inet),
('10.1.2.3'::inet)
) as i(a) order by a;
```

```text
a
----------------
10.1.2.3
192.168.1.1/23
192.168.1.0/24
192.168.1.0/25
10:23::ffff
(5 rows)
```

## Functions

### inet_client_addr

Check failure on line 104 in content/references/datatypes/inet.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'inet_client_addr'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'inet_client_addr'?", "location": {"path": "content/references/datatypes/inet.md", "range": {"start": {"line": 104, "column": 5}}}, "severity": "ERROR"}

`inet_client_addr()` returns the IP address of the client connected to the current session, `NULL` for connections via
Unix domain socket.

```sql
select inet_client_addr();
```

```text
inet_client_addr
------------------
192.168.1.42
(1 row)
```
Loading