Learn SQL/Intermediate/Date & Time/SQL CURRENT_TIMESTAMP

SQL CURRENT_TIMESTAMP

Returns the current date AND time together — the single most commonly used 'right now' function.

What & Why

CURRENT_TIMESTAMP returns the transaction timestamp. The worked query fixes it at 2024-03-31 12:00:00+00 while counting the real marketing.campaigns rows.

See How It Works

BUSINESS QUESTION

Using a fixed teaching clock, Marketing records a report timestamp beside the campaign count.

idnamechannelspendstart_dateend_datestatustarget_segment
1Spring Launchgoogle_ads55000.002024-01-152024-03-31activesmb
2Retention Webinaremail45000.002024-02-102024-04-15activeenterprise
3Finance Retargetinglinkedin50000.002024-03-122024-05-31activeenterprise
4Enterprise Searchgoogle_ads60000.002024-04-012024-06-30activeenterprise
EXAMPLE QUERY
-- In a live report, replace the teaching value with CURRENT_TIMESTAMP.
SELECT
  TIMESTAMPTZ '2024-03-31 12:00:00+00' AS generated_at,
  COUNT(*) AS campaign_count
FROM marketing.campaigns;
RESULT — exact output from the displayed Queryflo rows
generated_atcampaign_count
2024-03-31 12:00:00+004

The fixed timestamp represents CURRENT_TIMESTAMP beside the real campaign count.

Now You Try

Practice this concept

Return the fixed teaching timestamp 2024-03-31 12:00:00+00 beside the marketing.campaigns row count.

Available schema
marketing

Prefix tables with marketing.table_name.

generated_atcampaign_count
marketing.campaigns
ColumnType
idinteger
nametext
channeltext
spendnumeric
start_datedate
end_datedate
statustext
target_segmenttext
legacy_idtext
query.sql
Intermediate business practice

Sign up free to try it on a real business scenario