Skip to content

Commit

Permalink
refactor: change variables type from DATETIME to TIMESTAMP
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasEvilasio authored Oct 16, 2024
1 parent 22a1420 commit fe1d9a3
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions queries/models/utils/placas_antes_depois.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DECLARE plate STRING DEFAULT ''; -- plate of the vehicle to be monitored
DECLARE start_datetime DATETIME DEFAULT '2024-01-01T00:00:00'; -- Start time of the detection range
DECLARE end_datetime DATETIME DEFAULT '2024-01-01T00:00:00'; -- End time of the detection range
DECLARE start_datetime TIMESTAMP DEFAULT '2024-10-15T01:00:00.000Z'; -- Start timestamp of the detection range
DECLARE end_datetime TIMESTAMP DEFAULT '2024-10-15T01:00:00.000Z'; -- End timestamp of the detection range
DECLARE N INT64 DEFAULT 5; -- Number of minutes to look for records before and after the selected time

-- Select all radar readings
Expand All @@ -18,8 +18,8 @@ WITH all_readings AS (
FROM `rj-cetrio.ocr_radar.readings_*`
WHERE
DATETIME(datahora, "America/Sao_Paulo")
BETWEEN DATETIME_SUB(start_datetime, INTERVAL 1 DAY)
AND DATETIME_ADD(end_datetime, INTERVAL 1 DAY)
BETWEEN DATETIME(DATETIME_SUB(start_datetime, INTERVAL 1 DAY), "America/Sao_Paulo")
AND DATETIME(DATETIME_ADD(end_datetime, INTERVAL 1 DAY), "America/Sao_Paulo")
QUALIFY(row_num_duplicate) = 1
),

Expand Down Expand Up @@ -98,8 +98,8 @@ selected AS (
WHERE
placa = plate
AND datahora_local
BETWEEN start_datetime
AND end_datetime
BETWEEN DATETIME(start_datetime, "America/Sao_Paulo")
AND DATETIME(end_datetime, "America/Sao_Paulo")
),
-- Look for records before and after the selected reading time
before_and_after AS (
Expand Down

0 comments on commit fe1d9a3

Please sign in to comment.