Skip to content

Conversation

@xitep
Copy link
Contributor

@xitep xitep commented Nov 23, 2025

Right now sqlparser-rs injects the AS keyword in front of alias names unconditionally. As reported by #1875 or #1784 this leads to problems on Oracle databases. This patch preserves the original absence / presence of the keyword (implicit/explicit aliases) in "table-factor" position when rendered via Display.

  1. Some more effort could be invested to apply the same behavior for select-items (ie. projections in queries) and/or further nodes of the AST with an alias for which AS is optional. To unify the implementation within the parser and for clients, representing aliases could then be exposed not as pure Idents but maybe as something as:
struct Alias {
  explicit: bool,
  name: Ident,
}

impl Deref for Alias {
  type Target = Ident;
  ...
}

impl From<Alias> for Ident {
  ...
}
  1. The parser could be instructed / configured (either by ParserOptions or through a Dialect setting) to always produce "explicit" alias tokens. This would then always produce the "AS" keyword when render via Display. Ideally, there would be a VisitorMut::visit_(mut_)alias and clients could just apply their own setting easily. But this would be rather a nice-to-have.

  2. I'd greatly appreciate a critical look since my know-how regarding different DBs is quite limited. I hope I've not broken any of the existing dialects and also hope this PR helps "preserving the syntax round trip".

Right now `sqlparser-rs` inject the `AS` keyword in front of aliases
unconditionally. As reported by apache#1875 or apache#1784 this leads to problems on
Oracle databases.  This patch preserves the original absence / presence of the
keyword (implicit/explicit aliases) in "table-factor" position when rendered
via `Display`.

1. Some more effort could be invested to apply the same behavior for
`SelectItem`s (ie. projections in queries) and further nodes of the AST with
an alias for which `AS` is optional. To unify the implementation within the
parser and for clients, representing aliases could then be exposed not as pure
`Ident`s but maybe as something as:

```rust
struct Alias {
  explicit: bool,
  name: Ident,
}

impl Deref for Alias {
  type Target = Ident;
  ...
}

impl From<Alias> for Ident {
  ...
}
```

2. The parser could be instructed / configured (either by ParserOptions or
through a Dialect setting) to always produce "explicit" alias tokens. This
would then always produce the `AS` keyword when render via `Display`. Ideally,
there would be a `VisitorMut::visit_(mut_)alias` and clients could easily apply
their own preference.

3. I'd greatly appreciate a critical look since my know-how regarding
different DBs is quite limited. I hope I've not broken any of the existing
dialects and also hope this PR helps "preserving the syntax round trip".
@xitep xitep force-pushed the implicit-alias branch 2 times, most recently from 8abb21c to f4ca760 Compare November 23, 2025 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant