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

Open
#9,468 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@georgesittas is already working on this.

Since Dec 2, 2026.

  • #9472 by @georgesittas — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python, sql

Research direction

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.

Written by the indexing model from the issue text.

Description

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

Dominant language
Python
Stars
9.8k
Forks
1.5k
Avg merge
10h 54m
Merged PRs (30d)
310

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from tobymao/sqlglot

All issues in tobymao/sqlglot

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.