-
Notifications
You must be signed in to change notification settings - Fork 982
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 dbt.current_timestamp() #4741
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
<TabItem value="postgres" label="Sample output (PostgreSQL)"> | ||
|
||
```sql | ||
CURRENT_TIMESTAMP OR TIMESTAMP? |
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.
not sure which is the right output?
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.
I added suggestions for each adapter.
Here's how I determined the output:
-
Create an analyses file:
analyses/current_timestamp.sql
{{ dbt.current_timestamp() }}
-
Compile it and look at the output:
dbt compile --profile postgres
Look at the compiled output in
target/compiled/my_project/analyses/current_timestamp.sql
.
@@ -316,6 +318,51 @@ This macro yields the database-specific data type for a `TIMESTAMP` (which may o | |||
TIMESTAMP | |||
``` | |||
|
|||
### dbt.current_timestamp() | |||
|
|||
The `dbt.current_timestamp()` macro allows you to generate the current timestamp in a format suitable for database queries. This is useful when you need to capture the current date and time within your SQL queries or models. |
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.
@dbeatty10 is this the same for our other adapters? starburst, fabric, spark, databricks?
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.
The thing that is true across all adapters:
- This macro returns the current date and time for the system.
The things that may vary:
- whether the result is an aware or naive timestamp
- whether it corresponds to the start of the statement or the start of the transaction (or something else)
website/docs/reference/dbt-jinja-functions/cross-database-macros.md
Outdated
Show resolved
Hide resolved
website/docs/reference/dbt-jinja-functions/cross-database-macros.md
Outdated
Show resolved
Hide resolved
website/docs/reference/dbt-jinja-functions/cross-database-macros.md
Outdated
Show resolved
Hide resolved
website/docs/reference/dbt-jinja-functions/cross-database-macros.md
Outdated
Show resolved
Hide resolved
website/docs/reference/dbt-jinja-functions/cross-database-macros.md
Outdated
Show resolved
Hide resolved
website/docs/reference/dbt-jinja-functions/cross-database-macros.md
Outdated
Show resolved
Hide resolved
website/docs/reference/dbt-jinja-functions/cross-database-macros.md
Outdated
Show resolved
Hide resolved
@@ -316,6 +318,51 @@ This macro yields the database-specific data type for a `TIMESTAMP` (which may o | |||
TIMESTAMP | |||
``` | |||
|
|||
### dbt.current_timestamp() | |||
|
|||
The `dbt.current_timestamp()` macro allows you to generate the current timestamp in a format suitable for database queries. This is useful when you need to capture the current date and time within your SQL queries or models. |
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.
The thing that is true across all adapters:
- This macro returns the current date and time for the system.
The things that may vary:
- whether the result is an aware or naive timestamp
- whether it corresponds to the start of the statement or the start of the transaction (or something else)
website/docs/reference/dbt-jinja-functions/cross-database-macros.md
Outdated
Show resolved
Hide resolved
<TabItem value="postgres" label="Sample output (PostgreSQL)"> | ||
|
||
```sql | ||
CURRENT_TIMESTAMP OR TIMESTAMP? |
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.
I added suggestions for each adapter.
Here's how I determined the output:
-
Create an analyses file:
analyses/current_timestamp.sql
{{ dbt.current_timestamp() }}
-
Compile it and look at the output:
dbt compile --profile postgres
Look at the compiled output in
target/compiled/my_project/analyses/current_timestamp.sql
.
…os.md Co-authored-by: Doug Beatty <44704949+dbeatty10@users.noreply.github.com>
…os.md Co-authored-by: Doug Beatty <44704949+dbeatty10@users.noreply.github.com>
…os.md Co-authored-by: Doug Beatty <44704949+dbeatty10@users.noreply.github.com>
…os.md Co-authored-by: Doug Beatty <44704949+dbeatty10@users.noreply.github.com>
…os.md Co-authored-by: Doug Beatty <44704949+dbeatty10@users.noreply.github.com>
…os.md Co-authored-by: Doug Beatty <44704949+dbeatty10@users.noreply.github.com>
…os.md Co-authored-by: Doug Beatty <44704949+dbeatty10@users.noreply.github.com>
…os.md Co-authored-by: Doug Beatty <44704949+dbeatty10@users.noreply.github.com>
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.
Two non-blocking suggestions that would be very nice (but not mandatory) to resolve.
- The result may be an aware or naive timestamp. | ||
- The result may correspond to the start of the statement or the start of the transaction. | ||
|
||
Refer to your adapter's documentation for specific timestamp information. |
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.
I'm not aware of any adapter-specific documentation including information about timestamps.
So it seems like we should either:
a) open issues to add timestamp-specific info to each adapter, or
b) remove this line
Do you have a preference?
<Tabs> | ||
<TabItem value="bq" label="Sample output (BigQuery)"> | ||
|
||
```sql | ||
current_timestamp() | ||
``` | ||
</TabItem> | ||
|
||
<TabItem value="postgres" label="Sample output (PostgreSQL)"> | ||
|
||
```sql | ||
now() | ||
``` | ||
</TabItem> |
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.
All the other sample output on the page only includes Postgres. I think the idea there was so that we didn't need to keep ~30 macros x ~5 adapters = 150 different items up-to-date.
So it seems like we should either:
a) open issues to add sample output for each macro for each adapter, or
b) remove the sample output for current_timestamp
for BQ, Snowflake, Redshift
We could also choose to include examples across adapters for only the current_timestamp
macro, but that would be discordant.
My strong preference would be option b) in order to make things more simple and easier to keep up-to-date.
What do you think @mirnawong1 ?
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.
oh ok! i saw this issue dbt-labs/dbt-utils#597 and for some reason thought to add the other adapters!
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 keep it with postgres so it's a simple example!
website/docs/reference/dbt-jinja-functions/cross-database-macros.md
Outdated
Show resolved
Hide resolved
…os.md
this pr adds
dbt.current_timestamp()
macro to the cross database macro page.Resolves #3370