mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Timestamp Functions as a postgres til.
This commit is contained in:
@@ -21,6 +21,10 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
||||
|
||||
- [Not So Random](go/not-so-random.md)
|
||||
|
||||
### postgres
|
||||
|
||||
- [Timestamp Functions](postgres/timestamp-functions.md)
|
||||
|
||||
### rails
|
||||
|
||||
- [Attribute Was](rails/attribute-was.md)
|
||||
|
||||
28
postgres/timestamp-functions.md
Normal file
28
postgres/timestamp-functions.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Timestamp Functions
|
||||
|
||||
There are a handful of timestamp functions available in postgres. The most
|
||||
common one is probably `now()`. This is an alias of
|
||||
`transaction_timestamp()` which the postgres docs describe as:
|
||||
|
||||
> Current date and time (start of current transaction)
|
||||
|
||||
Two other interesting timestamp functions are `statement_timestamp()` and
|
||||
`clock_timestamp()`. The postgres docs describe `statement_timestamp()` as:
|
||||
|
||||
> Current date and time (start of current statement)
|
||||
|
||||
Using `statement_timestamp()` throughout a transaction will yield different
|
||||
results from statement to statement.
|
||||
|
||||
The postgres docs describe `clock_timestamp()` as:
|
||||
|
||||
> Current date and time (changes during statement execution)
|
||||
|
||||
Using `clock_timestamp()` may even yield different results depending on
|
||||
where it appears in a given statement.
|
||||
|
||||
Try running something like this to see:
|
||||
|
||||
```postgresql
|
||||
select clock_timestamp(), clock_timestamp(), clock_timestamp(), clock_timestamp();
|
||||
```
|
||||
Reference in New Issue
Block a user