Skip to content

Commit aa8462a

Browse files
committed
Fix timestamp panic: pass time.Time through instead of converting midnight to date string
The convertPgValue function was converting time.Time values at midnight to date-only strings ("2026-01-01"), which caused the SDK to panic when trying to parse them as timestamps for timestamptz columns.
1 parent a81ddcc commit aa8462a

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

resources/services/sync.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,10 @@ func convertPgValue(value any) any {
180180
return "(" + result + ")"
181181

182182
case time.Time:
183-
// SDK's date32 type expects "YYYY-MM-DD" format, not the full timestamp
184-
// that pgx returns for date columns.
185-
if v.Hour() == 0 && v.Minute() == 0 && v.Second() == 0 && v.Nanosecond() == 0 {
186-
return v.Format("2006-01-02")
187-
}
183+
// Always pass time.Time through — the SDK handles it natively for both
184+
// timestamp and date Arrow types. The previous midnight check incorrectly
185+
// converted timestamps at midnight to date-only strings, causing the SDK
186+
// to panic when parsing them as timestamps.
188187
return v
189188

190189
case pgtype.Date:

resources/services/sync_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,17 @@ func TestConvertPgValue_GeometryTypes(t *testing.T) {
133133
})
134134
}
135135

136-
func TestConvertPgValue_Date(t *testing.T) {
137-
t.Run("time.Time date-only", func(t *testing.T) {
136+
func TestConvertPgValue_Timestamp(t *testing.T) {
137+
t.Run("time.Time midnight passes through as time.Time", func(t *testing.T) {
138138
d := time.Date(2026, 1, 15, 0, 0, 0, 0, time.UTC)
139139
result := convertPgValue(d)
140-
assert.Equal(t, "2026-01-15", result)
140+
assert.Equal(t, d, result) // must stay time.Time, not become "2026-01-15"
141141
})
142142

143-
t.Run("time.Time with time component", func(t *testing.T) {
143+
t.Run("time.Time with time component passes through", func(t *testing.T) {
144144
d := time.Date(2026, 1, 15, 12, 30, 0, 0, time.UTC)
145145
result := convertPgValue(d)
146-
assert.Equal(t, d, result) // passthrough — not date-only
146+
assert.Equal(t, d, result)
147147
})
148148

149149
t.Run("pgtype.Date", func(t *testing.T) {

0 commit comments

Comments
 (0)