#1214·go-sqlite3

Scanning of timestamps not working when using "with time zone"

Author: coma64Created Feb 3, 2024Updated Jun 22, 2025

With a column of type "timestamp with time zone", like in the following table, sqlite3 doesn't convert it into a time.Time and scanning such a row into a time.Time field therefore fails.

sql
create table snippets(
    id binary(16) primary key,
    content text not null,
    created_at timestamp with time zone not null default CURRENT_TIMESTAMP
);

I traced this to SQLiteRows.nextSyncLocked() where you check whether rc.decltype[i] is any of date, datetime or timestamp but in my case it's timestamp with time zone causing the value to not be converted from a string.

go version: go version go1.21.3 darwin/arm64

Code

go
type Snippet struct {
	Id        string
	Content   string
	CreatedAt time.Time `db:"created_at"`
}

snippet := Snippet{
  Id:      id.String(),
  Content: content,
}

if err = s.db.GetContext(ctx, &snippet, "insert into snippets(id, content) values ($1, $2) returning created_at", binaryId, content); err != nil {
  return nil, fmt.Errorf("inserting snippet: %w", err)
}