Oracle: qualify quotes USER, UID, ORA_ROWSCN and CONNECT_BY_ISLEAF/ISCYCLE as if they were columns

オープン
#9,468 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

@georgesittas がすでに取り組んでいます。

2026年12月2日 から。

  • #9472 @georgesittas による — オープン

評価

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

調査の方向性

Start with Oracle dialect definitions, especially Oracle.PSEUDOCOLUMNS and the no-parentheses handling used for SYSDATE, then trace how qualify resolves these names against the schema. Reproduce with the supplied snippet and Oracle dialect. Done when the five names remain unquoted and are not treated as columns; an open linked pull request is already addressing this issue.

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

説明

Oracle's PSEUDOCOLUMNS covers ROWNUM, ROWID, LEVEL, OBJECT_ID and OBJECT_VALUE. It does not cover a few other pseudo-columns and no-paren functions. qualify therefore treats them as ordinary columns and quotes them. A quoted name means a column with that name to Oracle, so the rewritten query fails with ORA-00904.

LEVEL shows the expected behaviour in the same query.

Fully reproducible code snippet

Read and write dialect are both oracle. Checked on 30.36.0 and on main (a7124cf).

import sqlglot
from sqlglot.optimizer.qualify import qualify

schema = {"t": {"id": "INT", "parent_id": "INT"}}
for sql in [
    "SELECT USER, UID FROM t",
    "SELECT ORA_ROWSCN FROM t",
    "SELECT id, LEVEL, CONNECT_BY_ISLEAF, CONNECT_BY_ISCYCLE FROM t "
    "START WITH parent_id IS NULL CONNECT BY NOCYCLE PRIOR id = parent_id",
]:
    tree = qualify(sqlglot.parse_one(sql, read="oracle"), schema=schema,
                   dialect="oracle", validate_qualify_columns=False)
    print(tree.sql(dialect="oracle"))

Output:

SELECT "USER" AS "USER", "UID" AS "UID" FROM "T" "T"
SELECT "ORA_ROWSCN" AS "ORA_ROWSCN" FROM "T" "T"
SELECT "T"."ID" AS "ID", LEVEL AS "LEVEL", "CONNECT_BY_ISLEAF" AS "CONNECT_BY_ISLEAF", "CONNECT_BY_ISCYCLE" AS "CONNECT_BY_ISCYCLE" FROM "T" "T" START WITH ...

Expected: USER, UID, ORA_ROWSCN, CONNECT_BY_ISLEAF and CONNECT_BY_ISCYCLE stay unquoted, the way LEVEL does. They should also not be treated as columns of t.

A possible fix: add ORA_ROWSCN, CONNECT_BY_ISLEAF and CONNECT_BY_ISCYCLE to Oracle.PSEUDOCOLUMNS; the last two only apply under CONNECT BY, like LEVEL. USER and UID are functions rather than pseudo-columns, so they may fit better as no-paren functions, the way SYSDATE is handled. Happy to open a PR.

Official Documentation

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

環境構築

はじめの一歩

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

tobymao/sqlglot のほかの issue

tobymao/sqlglot の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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