Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3a3e978
Bring EXTRACT into alignment with PostgreSQL v14
jkosh44 Jan 10, 2022
d155340
Clean up generics with DecimalLike
jkosh44 Jan 14, 2022
fbce708
Merge branch 'main' of github.com:MaterializeInc/materialize into jko…
jkosh44 Jan 14, 2022
c4cced3
Remove unnecessary nanoseconds from DateLike epoch
jkosh44 Jan 15, 2022
1d9cfb2
Merge branch 'main' of github.com:MaterializeInc/materialize into jko…
jkosh44 Jan 19, 2022
2158f75
Merge branch 'main' of github.com:MaterializeInc/materialize into jko…
jkosh44 Jan 21, 2022
7d5c5c1
Merge branch 'main' of github.com:MaterializeInc/materialize into jko…
jkosh44 Jan 22, 2022
a43a0dd
Fix user docs
jkosh44 Jan 24, 2022
92b9213
Remove mention of Ingres and date_part from extract docs
jkosh44 Jan 25, 2022
d6b93f0
Hoist generics up a level
jkosh44 Jan 25, 2022
e5f4345
Pushed unwrapping Datums down where possible
jkosh44 Jan 25, 2022
70317bd
Remove Ingres from and SQL standard from date-part docs
jkosh44 Jan 25, 2022
8733cf1
Merge branch 'main' of github.com:MaterializeInc/materialize into jko…
jkosh44 Jan 25, 2022
3fc700d
Remove alias from docs
jkosh44 Jan 25, 2022
b4c9906
Merge branch 'main' of github.com:MaterializeInc/materialize into jko…
jkosh44 Jan 25, 2022
bd496cd
Fix release notes
jkosh44 Jan 25, 2022
de66b42
Merge branch 'main' of github.com:MaterializeInc/materialize into jko…
jkosh44 Jan 27, 2022
1ea3baa
Fix lint issues
jkosh44 Jan 31, 2022
bcbfec7
Add date-part diagram
jkosh44 Jan 31, 2022
7faaf6f
Fix date-part test
jkosh44 Jan 31, 2022
b9ad09a
Fix test error msg
jkosh44 Jan 31, 2022
45b95cc
Fix release notes link
jkosh44 Jan 31, 2022
010d994
Fix testdrive
jkosh44 Jan 31, 2022
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
14 changes: 14 additions & 0 deletions doc/user/content/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,20 @@ changes that have not yet been documented.
- Fix a bug where using a `ROWS FROM` clause with an alias in a view would cause
Materialize to fail to reboot {{% gh 10008 %}}.

- **Breaking change.** Return an error when [`extract`](/sql/functions/extract/)
is called with a [`date`] value but a time-related field (e.g., `SECOND`).

Previous versions of Materialize would incorrectly return `0` in these cases.
The new behavior matches PostgreSQL.

[`date_part`](/sql/functions/date_part/) still returns a `0` in these cases,
which matches the PostgreSQL behavior.

- **Breaking change.** Change the return type of [`extract`](/sql/functions/extract/)
from [`float`](/sql/types/float/) to [`numeric`](/sql/types/numeric/).

This new behavior matches PostgreSQL v14.

{{< comment >}}
Only add new release notes above this line.

Expand Down
75 changes: 75 additions & 0 deletions doc/user/content/sql/functions/date_part.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
title: "date_part Function"
description: "Returns a specified time component from a time-based value"
menu:
main:
parent: 'sql-functions'
---

`date_part` is modeled on the traditional Ingres equivalent to the SQL-standard
function [`EXTRACT`](../extract). For PostgreSQL compatibility, `date_part` returns values of type
[`float`](../../types/float). This can result in a loss of precision in certain uses. Using
[`EXTRACT`](../extract) is recommended instead.

## Signatures

TODO: this svg doesn't exist
Comment thread
jkosh44 marked this conversation as resolved.
Outdated
{{< diagram "func-date-part.svg" >}}

Parameter | Type | Description
----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|------------
_val_ | [`time`](../../types/time), [`timestamp`](../../types/timestamp), [`timestamp with time zone`](../../types/timestamptz), [`interval`](../../types/interval), [`date`](../../types/date) | The value from which you want to extract a component. vals of type [`date`](../../types/date) are first cast to type [`timestamp`](../../types/timestamp).

### Arguments

`date_part` supports multiple synonyms for most time periods.

Time period | Synonyms
------------|---------
epoch | `EPOCH`
millennium | `MIL`, `MILLENNIUM`, `MILLENNIA`
century | `C`, `CENT`, `CENTURY`, `CENTURIES`
decade | `DEC`, `DECS`, `DECADE`, `DECADES`
year | `Y`, `YEAR`, `YEARS`, `YR`, `YRS`
quarter | `QTR`, `QUARTER`
month | `MON`, `MONS`, `MONTH`, `MONTHS`
week | `W`, `WEEK`, `WEEKS`
day | `D`, `DAY`, `DAYS`
hour |`H`, `HR`, `HRS`, `HOUR`, `HOURS`
minute | `M`, `MIN`, `MINS`, `MINUTE`, `MINUTES`
second | `S`, `SEC`, `SECS`, `SECOND`, `SECONDS`
microsecond | `US`, `USEC`, `USECS`, `USECONDS`, `MICROSECOND`, `MICROSECONDS`
millisecond | `MS`, `MSEC`, `MSECS`, `MSECONDS`, `MILLISECOND`, `MILLISECONDS`
day of week |`DOW`
ISO day of week | `ISODOW`
day of year | `DOY`

### Return value

`date_part` returns a [`float`](../../types/float) value.

## Examples

### Extract second from timestamptz

```sql
SELECT date_part('S', TIMESTAMP '2006-01-02 15:04:05.06')
AS sec_extr;
```
```nofmt
sec_extr
----------
5.06
```

### Extract century from date

```sql
SELECT date_part('CENTURIES', DATE '2006-01-02')
AS sec_extr;
```
```nofmt
sec_extr
----------
21
```
10 changes: 6 additions & 4 deletions doc/user/content/sql/functions/extract.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ menu:

`EXTRACT` returns some time component from a time-based value, such as the year from a Timestamp.

See [`date_part`](../date_part) for the traditional Ingres equivalent function.
Comment thread
jkosh44 marked this conversation as resolved.
Outdated

## Signatures

{{< diagram "func-extract.svg" >}}

Parameter | Type | Description
----------|-----------------------------------------------------------------------------------------------------------------------------------------------------|------------
_val_ | [`date`](../../types/date), [`time`](../../types/time), [`timestamp`](../../types/timestamp), [`timestamp with time zone`](../../types/timestamptz) | The value from which you want to extract a component.
Parameter | Type | Description
----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------
_val_ | [`date`](../../types/date), [`time`](../../types/time), [`timestamp`](../../types/timestamp), [`timestamp with time zone`](../../types/timestamptz), [`interval`](../../types/interval) | The value from which you want to extract a component.

### Arguments

Expand Down Expand Up @@ -42,7 +44,7 @@ decade | `DEC`, `DECS`, `DECADE`, `DECADES`

### Return value

`EXTRACT` returns a [`float`](../../types/float) value.
`EXTRACT` returns a [`numeric`](../../types/numeric) value.

## Examples

Expand Down
Loading