Extract the whole-second component (0 through 59) from a timestamp.
SECOND(timestamp)
## Overview Extracts the whole-second component from a TIMESTAMP (or TIME) value, returned as an INTEGER between 0 and 59. Fractional-second precision is discarded; use EXTRACT(SECOND FROM ts) if you need the fractional part included. Use SECOND for fine-grained time-of-minute filtering, sub-minute bucketing, and second-level scheduling logic. ## Behavior - Returns an INTEGER in the range 0 through 59. - Returns NULL if the argument is NULL. - Accepts TIMESTAMP, TIMESTAMP WITH TIME ZONE, and TIME inputs. - Truncates sub-second precision; SECOND(TIMESTAMP '...14:30:45.789') returns 45. - For fractional seconds use EXTRACT(SECOND FROM ts) which returns a DOUBLE including the fractional part. ## Timezone handling - TIMESTAMP WITH TIME ZONE values are converted to the session zone first. Seconds are unaffected by zone offset in all standard zones. ## Compatibility - Integer-second shorthand for EXTRACT(SECOND FROM source). EXTRACT returns a DOUBLE that includes fractional seconds; SECOND as a scalar function returns an INTEGER.
| Name | Type | Description |
|---|---|---|
timestamp | Specifies the timestamp or time value from which to extract the second component. |
-- Whole seconds within the minute
SELECT SECOND(TIMESTAMP '2025-03-15 14:30:45') AS s;
-- Top of the minute returns 0
SELECT SECOND(TIMESTAMP '2025-03-15 09:00:00') AS s;
-- Filter events exactly on the minute mark
SELECT event_id FROM telemetry.web.requests WHERE SECOND(event_ts) = 0;
-- Distribution of events across the 60 seconds of the minute
SELECT SECOND(event_ts) AS s, COUNT(*) AS events
FROM telemetry.web.requests
GROUP BY s
ORDER BY s;
-- Fractional-second handling: SECOND returns only the integer portion
SELECT SECOND(TIMESTAMP '2025-03-15 14:30:45.789') AS whole_sec;