From 9c82d308df1ebd22ca710cb6b4f158299df90436 Mon Sep 17 00:00:00 2001 From: Jack Platten Date: Thu, 30 Apr 2026 15:14:04 -0700 Subject: [PATCH] set undef to 0 --- migrations/20250101000000_change_time_us_to_bigint.sql | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/migrations/20250101000000_change_time_us_to_bigint.sql b/migrations/20250101000000_change_time_us_to_bigint.sql index 6c01c2b..d94b4b7 100644 --- a/migrations/20250101000000_change_time_us_to_bigint.sql +++ b/migrations/20250101000000_change_time_us_to_bigint.sql @@ -1,4 +1,9 @@ -- Change time_us from TEXT to BIGINT. --- The existing values are stored as microsecond epoch strings and cast cleanly. +-- First, replace any invalid values (like "undef") with 0. +UPDATE posts +SET time_us = '0' +WHERE time_us = 'undef' OR time_us !~ '^\d+$'; + +-- Now cast the column to BIGINT ALTER TABLE posts ALTER COLUMN time_us TYPE BIGINT USING time_us::BIGINT; -- 2.51.2