Skip to content

Support timestamp type with precision #186

@muety

Description

@muety

As part of scanning database rows, this piece of code tries to guess whether the column is meant to contain temporal values, based on the table's DDL. However, this does not support timestamp with an explicit precision being set (like TIMESTAMP(3). While this syntax is probably not official SQL standard, it might especially occur in cases where multiple databases are supported (e.g. through an ORM like GORM). For example, in Postgres, this is a legitimate way to define timestamp columns.

Consider the following minimal code example.

package main

import (
	"database/sql"
	_ "github.com/glebarez/go-sqlite"
	"log"
	"time"
)

/*
	CREATE TABLE foo (id integer PRIMARY KEY AUTOINCREMENT, created_at TIMESTAMP(3));
	INSERT INTO foo (created_at) VALUES ('2025-08-29T10:00:00.000+02:00');
*/

func main() {
	db, err := sql.Open("sqlite", "file:test.db")
	if err != nil {
		log.Fatal(err)
	}

	var (
		Id int
		CreatedAt time.Time
	)

	if err := db.QueryRow("select * from foo").Scan(&Id, &CreatedAt); err != nil {
		log.Fatal(err)
	}
}

Result:

sql: Scan error on column index 2, name "created_at": unsupported Scan, storing driver.Value type string into type *time.Time
exit status 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions