-
Notifications
You must be signed in to change notification settings - Fork 504
Bring EXTRACT into alignment with PostgreSQL v14 #10027
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 8 commits
3a3e978
d155340
fbce708
c4cced3
1d9cfb2
2158f75
7d5c5c1
a43a0dd
92b9213
d6b93f0
e5f4345
70317bd
8733cf1
3fc700d
b4c9906
bd496cd
de66b42
1ea3baa
bcbfec7
7faaf6f
b9ad09a
45b95cc
010d994
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 |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| --- | ||
| 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 | ||
|
|
||
| {{< 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; | ||
|
jkosh44 marked this conversation as resolved.
Outdated
|
||
| ``` | ||
| ```nofmt | ||
| sec_extr | ||
| ---------- | ||
| 21 | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
|
Contributor
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. It makes sense to point people from date_part to extract because extract is the new preferred way. Does it make sense to not even link people from extract to date_part, and instead remove this sentence?
Contributor
Author
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. I removed this sentence. |
||
|
|
||
| ## 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 | ||
|
|
||
|
|
@@ -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 | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.