diff --git a/internal/value.go b/internal/value.go index 69fb72f..457362c 100644 --- a/internal/value.go +++ b/internal/value.go @@ -304,15 +304,6 @@ func (sv StringValue) ToTime() (time.Time, error) { case isTimestamp(raw): return parseTimestamp(raw, time.UTC) } - if f, err := strconv.ParseFloat(raw, 64); err == nil { - return TimestampFromFloatValue(f) - } - if i64, err := strconv.ParseInt(raw, 10, 64); err == nil { - if i64 > time.Unix(0, 0).Unix()*int64(time.Millisecond) { - return TimestampFromInt64Value(i64) - } - return DateFromInt64Value(i64) - } return time.Time{}, fmt.Errorf("failed to convert %s to time.Time type", sv) } diff --git a/query_test.go b/query_test.go index e0de653..0d9102b 100644 --- a/query_test.go +++ b/query_test.go @@ -2951,6 +2951,12 @@ SELECT item FROM Produce WHERE Produce.category = 'vegetable' QUALIFY RANK() OVE query: `SELECT CAST("apple" AS INT64) AS not_a_number`, expectedErr: `failed to analyze: INVALID_ARGUMENT: Could not cast literal "apple" to type INT64 [at 1:13]`, }, + // Regression test for goccy/go-zetasqlite#175 + { + name: "cast integer to datetime", + query: `WITH toks AS (SELECT "20100317" AS dt) SELECT CAST(dt AS DATETIME) FROM toks;`, + expectedErr: "failed to convert 20100317 to time.Time type", + }, { name: "safe cast", query: `SELECT SAFE_CAST(x AS STRING) FROM UNNEST([1, 2, 3]) AS x`,