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

Add docs for VARINT #4669

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Changes from 1 commit
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
35 changes: 23 additions & 12 deletions docs/sql/data_types/numeric.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,32 @@ The types `UTINYINT`, `USMALLINT`, `UINTEGER`, `UBIGINT` and `UHUGEINT` store wh

<div class="center_aligned_header_table"></div>

| Name | Aliases | Min | Max |
| :---------- | :------------------------------- | ---------------------------------------: | --------------------------------------: |
| `TINYINT` | `INT1` | -128 | 127 |
| `SMALLINT` | `INT2`, `INT16` `SHORT` | -32768 | 32767 |
| `INTEGER` | `INT4`, `INT32`, `INT`, `SIGNED` | -2147483648 | 2147483647 |
| `BIGINT` | `INT8`, `INT64` `LONG` | -9223372036854775808 | 9223372036854775807 |
| `HUGEINT` | `INT128` | -170141183460469231731687303715884105728 | 170141183460469231731687303715884105727 |
| `UTINYINT` | - | 0 | 255 |
| `USMALLINT` | - | 0 | 65535 |
| `UINTEGER` | - | 0 | 4294967295 |
| `UBIGINT` | - | 0 | 18446744073709551615 |
| `UHUGEINT` | - | 0 | 340282366920938463463374607431768211455 |
| Name | Aliases | Min | Max | Size&nbsp;in&nbsp;Bytes |
| :---------- | :------------------------------- | ---------------------------------------: | --------------------------------------: | ----------------: |
| `TINYINT` | `INT1` | -128 | 127 | 1 |
| `SMALLINT` | `INT2`, `INT16` `SHORT` | -32768 | 32767 | 2 |
| `INTEGER` | `INT4`, `INT32`, `INT`, `SIGNED` | -2147483648 | 2147483647 | 4 |
| `BIGINT` | `INT8`, `INT64` `LONG` | -9223372036854775808 | 9223372036854775807 | 8 |
| `HUGEINT` | `INT128` | -170141183460469231731687303715884105728 | 170141183460469231731687303715884105727 | 16 |
| `UTINYINT` | - | 0 | 255 | 1 |
| `USMALLINT` | - | 0 | 65535 | 2 |
| `UINTEGER` | - | 0 | 4294967295 | 4 |
| `UBIGINT` | - | 0 | 18446744073709551615 | 8 |
| `UHUGEINT` | - | 0 | 340282366920938463463374607431768211455 | 16 |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could also add VARINT here?

Copy link
Contributor Author

@Tishj Tishj Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's a good idea.
The minimum and maximum are both incredibly huge, and the Size in Bytes is variable, which is exactly why I've made a separate section for it.

I do understand why it would fit there, because it is just a numeric like the others in the list, but it's giant

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that's a summary, on top of the page, and most likely the only thing that 99.9% of the people will read from it, so that's why I think is important to add it there. The ranges might look "confusing" at first glance, but then readers can check the actual varint description you added, if it's not immediately clear to them.

I think for bytes you can have the range 4 - 2ˆ23 bytes. Min and max can be a value * 10^...

I can also do that in a later PR.


The type integer is the common choice, as it offers the best balance between range, storage size, and performance. The `SMALLINT` type is generally only used if disk space is at a premium. The `BIGINT` and `HUGEINT` types are designed to be used when the range of the integer type is insufficient.

## Variable Integer

The previously mentioned integer types all have in common that the numbers in the `Min` and `Max` range all have the same storage size, UTINYINT is 1 byte, SMALLINT is 2 bytes, etc..
But sometimes you need numbers that are even bigger than what is supported by a HUGEINT!

For those situations the VARINT type can come in handy, as the VARINT type has a MUCH bigger limit (the value can consist of up to 1262612 digits).
The minimum storage size for a VARINT is 4 bytes, every digit takes up an extra bit, rounded up to 8 (12 digits take 12 bits, rounded up to 16, becomes two extra bytes).

Both negative and positive values are supported by the VARINT type.


## Fixed-Point Decimals

The data type `DECIMAL(WIDTH, SCALE)` (also available under the alias `NUMERIC(WIDTH, SCALE)`) represents an exact fixed-point decimal value. When creating a value of type `DECIMAL`, the `WIDTH` and `SCALE` can be specified to define which size of decimal values can be held in the field. The `WIDTH` field determines how many digits can be held, and the `scale` determines the amount of digits after the decimal point. For example, the type `DECIMAL(3, 2)` can fit the value `1.23`, but cannot fit the value `12.3` or the value `1.234`. The default `WIDTH` and `SCALE` is `DECIMAL(18, 3)`, if none are specified.
Expand Down