-
Notifications
You must be signed in to change notification settings - Fork 473
New docs on expressions and constants #1008
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,13 +8,21 @@ The `DATE` [data type](data-types.html) stores a year, month, and day. | |
|
||
<div id="toc"></div> | ||
|
||
## Format | ||
## Syntax | ||
|
||
When inserting into a `DATE` column, format the value as `DATE '2016-01-25'`. | ||
A constant value of type `DATE` can be expressed using an | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's change this section title to |
||
[interpreted literal](sql-constants.html#interpreted-literals), or a | ||
string literal | ||
[annotated with](sql-expressions.html#explicitly-typed-expressions) | ||
type `DATE` or | ||
[coerced to](sql-expressions.html#explicit-type-coercions) type | ||
`DATE`. | ||
|
||
Alternatively, you can use a string literal, e.g., `'2016-01-25'`, which CockroachDB will resolve into the `DATE` type. | ||
The string format for dates is `YYYY-MM-DD`. For example: `DATE '2016-12-23'`. | ||
|
||
Note that in some contexts, dates may be displayed with hours, minutes, seconds, and timezone set to 0. | ||
CockroachDB also supports using uninterpreted | ||
[string literals](sql-constants.html#string-literals) in contexts | ||
where a `DATE` value is otherwise expected. | ||
|
||
## Size | ||
|
||
|
@@ -36,15 +44,20 @@ A `DATE` column supports values up to 8 bytes in width, but the total storage si | |
+-------+------+-------+---------+ | ||
~~~ | ||
~~~ sql | ||
> -- explicitly typed DATE literal | ||
> INSERT INTO dates VALUES (DATE '2016-03-26', 12345); | ||
|
||
> -- string literal implicitly typed as DATE | ||
> INSERT INTO dates VALUES ('2016-03-27', 12345); | ||
|
||
> SELECT * FROM dates; | ||
~~~ | ||
~~~ | ||
+---------------------------+-------+ | ||
| a | b | | ||
+---------------------------+-------+ | ||
| 2016-03-26 00:00:00+00:00 | 12345 | | ||
| 2016-03-27 00:00:00+00:00 | 12345 | | ||
+---------------------------+-------+ | ||
~~~ | ||
|
||
|
@@ -64,4 +77,4 @@ Type | Details | |
|
||
## See Also | ||
|
||
[Data Types](data-types.html) | ||
[Data Types](data-types.html) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,10 @@ summary: The FLOAT data type stores inexact, floating-point numbers with up to 1 | |
toc: false | ||
--- | ||
|
||
The `FLOAT` [data type](data-types.html) stores inexact, floating-point numbers with up to 17 digits in total and at least one digit to the right of the decimal point. | ||
The `FLOAT` [data type](data-types.html) stores inexact, floating-point numbers with up to 17 digits of decimal precision. | ||
|
||
They are handled internally using the [standard double-precision | ||
(64-bit binary-encoded) IEEE754 format](https://en.wikipedia.org/wiki/IEEE_floating_point). | ||
|
||
<div id="toc"></div> | ||
|
||
|
@@ -15,14 +18,20 @@ In CockroachDB, the following are aliases for `FLOAT`: | |
- `REAL` | ||
- `DOUBLE PRECISION` | ||
|
||
## Format | ||
## Syntax | ||
|
||
When inserting into a `FLOAT` column, format the value as a numeric literal, e.g., `1.2345` or `1`. | ||
A constant value of type `FLOAT` can be entered as a [numeric literal](sql-constants.html#numeric-literals). | ||
For example: `1.414` or `-1234`. | ||
|
||
Alternately, you can cast `+Inf` (positive infinity), `-Inf` (negative infinity), or `NaN` (not a number) as a float: | ||
The special IEEE754 values for positive infinity, negative infinity | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
and Not A Number (NaN) cannot be entered using numeric literals | ||
directly and must be converted using an | ||
[interpreted literal](sql-constants.html#interpreted-literals) or an | ||
[explicit conversion](sql-expressions.html#explicit-type-coercions) from | ||
a string literal instead. For example: | ||
|
||
- `CAST('+Inf' AS FLOAT)` | ||
- `CAST('-Inf' AS FLOAT)` | ||
- `FLOAT '+Inf'` | ||
- `'-Inf'::FLOAT` | ||
- `CAST('NaN' AS FLOAT)` | ||
|
||
## Size | ||
|
@@ -61,16 +70,15 @@ A `FLOAT` column supports values up to 8 bytes in width, but the total storage s | |
|
||
## Supported Casting & Conversion | ||
|
||
`DECIMAL` values can be [cast](data-types.html#data-type-conversions--casts) to any of the following data types: | ||
`FLOAT` values can be [cast](data-types.html#data-type-conversions--casts) to any of the following data types: | ||
|
||
Type | Details | ||
-----|-------- | ||
`INT` | Truncates decimal precision and requires values to be between -2^63 and 2^63-1 | ||
`DECIMAL` | –– | ||
`DECIMAL` | Causes an error to be reported if the value is NaN or +/- Inf. | ||
`BOOL` | **0** converts to `false`; all other values convert to `true` | ||
|
||
{{site.data.alerts.callout_info}}Because the <a href="serial.html"><code>SERIAL</code> data type</a> represents values automatically generated CockroachDB to uniquely identify rows, you cannot meaningfully cast other data types as <code>SERIAL</code> values.{{site.data.alerts.end}} | ||
`STRING` | -- | ||
|
||
## See Also | ||
|
||
[Data Types](data-types.html) | ||
[Data Types](data-types.html) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's change this section title to
Syntax
and rewrite the first sentence as:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done