Skip to content
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

Merged
merged 29 commits into from
Jan 18, 2024
Merged

add dbt.current_timestamp() #4741

merged 29 commits into from
Jan 18, 2024

Conversation

mirnawong1
Copy link
Contributor

@mirnawong1 mirnawong1 commented Jan 12, 2024

this pr adds dbt.current_timestamp() macro to the cross database macro page.

Resolves #3370

@mirnawong1 mirnawong1 requested a review from a team as a code owner January 12, 2024 13:23
Copy link

vercel bot commented Jan 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-getdbt-com ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 18, 2024 3:00pm

@github-actions github-actions bot added content Improvements or additions to content size: small This change will take 1 to 2 days to address Docs team Authored by the Docs team @dbt Labs labels Jan 12, 2024
<TabItem value="postgres" label="Sample output (PostgreSQL)">

```sql
CURRENT_TIMESTAMP OR TIMESTAMP?
Copy link
Contributor Author

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?

Copy link
Contributor

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:

  1. Create an analyses file:

    analyses/current_timestamp.sql

    {{ dbt.current_timestamp() }}
  2. 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.
Copy link
Contributor Author

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?

Copy link
Contributor

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)

@@ -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.
Copy link
Contributor

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)

<TabItem value="postgres" label="Sample output (PostgreSQL)">

```sql
CURRENT_TIMESTAMP OR TIMESTAMP?
Copy link
Contributor

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:

  1. Create an analyses file:

    analyses/current_timestamp.sql

    {{ dbt.current_timestamp() }}
  2. 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.

mirnawong1 and others added 8 commits January 12, 2024 15:16
…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>
@github-actions github-actions bot added size: medium This change will take up to a week to address and removed size: small This change will take 1 to 2 days to address labels Jan 15, 2024
Copy link
Contributor

@dbeatty10 dbeatty10 left a 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.
Copy link
Contributor

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?

Comment on lines 340 to 353
<Tabs>
<TabItem value="bq" label="Sample output (BigQuery)">

```sql
current_timestamp()
```
</TabItem>

<TabItem value="postgres" label="Sample output (PostgreSQL)">

```sql
now()
```
</TabItem>
Copy link
Contributor

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 ?

Copy link
Contributor Author

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!

Copy link
Contributor Author

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!

@github-actions github-actions bot added size: small This change will take 1 to 2 days to address and removed size: medium This change will take up to a week to address labels Jan 18, 2024
@mirnawong1 mirnawong1 enabled auto-merge January 18, 2024 14:53
@mirnawong1 mirnawong1 merged commit fe82b6d into current Jan 18, 2024
7 checks passed
@mirnawong1 mirnawong1 deleted the mwong-cross-db-macros branch January 18, 2024 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto update content Improvements or additions to content Docs team Authored by the Docs team @dbt Labs January-2024 size: small This change will take 1 to 2 days to address
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cross-database current_timestamp() macro
3 participants