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

Abierto
#9,468 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@georgesittas ya está trabajando en esto.

Desde el 2/12/2026.

  • #9472 de @georgesittas — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
python, sql

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Python
Estrellas
9.8k
Forks
1.5k
Merge medio
10 h 54 min
PR fusionados (30 d)
310

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de tobymao/sqlglot

Todos los issues de tobymao/sqlglot

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.