prql icon indicating copy to clipboard operation
prql copied to clipboard

[oracle] `OracleDialect` should not use `AS` for table aliases

Open julien-pinchelimouroux opened this issue 2 months ago • 1 comments

What happened?

Oracle has no AS keyword for table aliases: its table_reference grammar is table_reference [ t_alias ]. Column aliases do accept AS, table aliases do not. The sql.oracle target currently emits AS for them, so any query with an aliased relation is rejected by the server.

PRQL input

from a = bar

SQL output

SELECT * FROM "bar" AS "a"

Expected SQL output

SELECT * FROM "bar" "a"

MVCE confirmation

  • [x] Minimal example
  • [x] New issue

Anything else?

No response

julien-pinchelimouroux avatar Sep 10 '26 16:09 julien-pinchelimouroux

Reproduced and fixed in #6306 — it still needs maintainer review before it lands.

The cause is narrower than the target: simple_table_alias in gen_query.rs hard-coded sqlparser's TableAlias { explicit: true, .. }, and that flag is what renders the AS. Nothing consulted the dialect, so the PR adds a table_alias_uses_as dialect method that OracleDialect turns off.

Worth knowing if you hit this elsewhere: the same helper builds the alias for aliased join operands and for the derived tables the compiler generates itself in a set operation, so join c = baz (==id) and append were emitting the same invalid AS. All three are covered by the regression test. Column aliases are on a separate path and keep their AS, which Oracle accepts.

prql-bot avatar Sep 10 '26 16:09 prql-bot