SQLite: CAST AS TIMESTAMPTZ (MySQL TIMESTAMP) becomes a number

オープン 初心者向け
#9,304 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
74/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
mysql, python, sql, sqlite
領域
databases

調査の方向性

スニペットで再現し、次に sqlglot/dialects/sqlite.py を読む。そこでは cast が生成され、TIMESTAMP はすでに DATETIME(x) にマップされている。TIMESTAMPTZ/TIMESTAMPLTZ が素の CAST にフォールスルーする型マッピングを見つける。対応するエントリを追加し、tests/dialects/test_sqlite.py の fixture を MySQL のラウンドトリップで拡張する。トランスパイルされた SQLite 出力が timestamp のテキストを保持し、interval 演算が年 2024 を裸の数値として返さなくなったら完了。

索引モデルが issue の本文から書いたものです。

説明

MySQL's TIMESTAMP type parses as TIMESTAMPTZ, and the SQLite generator writes CAST(x AS TIMESTAMPTZ). SQLite gives that declared type NUMERIC affinity, so the cast turns the timestamp text into a number:

import sqlite3, sqlglot
sql = sqlglot.transpile("SELECT CAST('2024-01-15 23:30:00' AS TIMESTAMP)", read="mysql", write="sqlite")[0]
# "SELECT CAST('2024-01-15 23:30:00' AS TIMESTAMPTZ)"
sqlite3.connect(":memory:").execute(sql).fetchall()   # [(2024,)]

Interval arithmetic on it then produces dates like '-4707-06-10' (DATE(CAST(... AS TIMESTAMPTZ), '1 DAY')). A plain TIMESTAMP cast is written as DATETIME(x); writing TIMESTAMPTZ and TIMESTAMPLTZ casts the same way would keep the text.

I found this while running BenchBox benchmarks on SQLite. The issue was drafted with Claude.

主要言語
Python
スター
9.8k
フォーク
1.4k
平均マージ
10時間 52分
マージ済み PR(30日)
303

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

tobymao/sqlglot のほかの issue

tobymao/sqlglot の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。