Commit f4ca760
committed
Implicit aliases
Right now `sqlparser-rs` inject the `AS` keyword in front of aliases
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
`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".1 parent 2b8e99c commit f4ca760
File tree
10 files changed
+202
-269
lines changed- src
- ast
- parser
- tests
10 files changed
+202
-269
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1902 | 1902 | | |
1903 | 1903 | | |
1904 | 1904 | | |
1905 | | - | |
| 1905 | + | |
1906 | 1906 | | |
1907 | 1907 | | |
1908 | 1908 | | |
| |||
1932 | 1932 | | |
1933 | 1933 | | |
1934 | 1934 | | |
1935 | | - | |
| 1935 | + | |
1936 | 1936 | | |
1937 | 1937 | | |
1938 | 1938 | | |
| |||
1948 | 1948 | | |
1949 | 1949 | | |
1950 | 1950 | | |
1951 | | - | |
| 1951 | + | |
1952 | 1952 | | |
1953 | 1953 | | |
1954 | 1954 | | |
1955 | 1955 | | |
1956 | 1956 | | |
1957 | 1957 | | |
1958 | | - | |
| 1958 | + | |
1959 | 1959 | | |
1960 | 1960 | | |
1961 | 1961 | | |
| |||
1973 | 1973 | | |
1974 | 1974 | | |
1975 | 1975 | | |
1976 | | - | |
| 1976 | + | |
1977 | 1977 | | |
1978 | 1978 | | |
1979 | 1979 | | |
1980 | 1980 | | |
1981 | 1981 | | |
1982 | | - | |
| 1982 | + | |
1983 | 1983 | | |
1984 | 1984 | | |
1985 | 1985 | | |
| |||
1995 | 1995 | | |
1996 | 1996 | | |
1997 | 1997 | | |
1998 | | - | |
| 1998 | + | |
1999 | 1999 | | |
2000 | 2000 | | |
2001 | 2001 | | |
| |||
2014 | 2014 | | |
2015 | 2015 | | |
2016 | 2016 | | |
2017 | | - | |
| 2017 | + | |
2018 | 2018 | | |
2019 | 2019 | | |
2020 | 2020 | | |
| |||
2024 | 2024 | | |
2025 | 2025 | | |
2026 | 2026 | | |
2027 | | - | |
| 2027 | + | |
2028 | 2028 | | |
2029 | 2029 | | |
2030 | 2030 | | |
| |||
2051 | 2051 | | |
2052 | 2052 | | |
2053 | 2053 | | |
2054 | | - | |
2055 | | - | |
| 2054 | + | |
| 2055 | + | |
2056 | 2056 | | |
2057 | 2057 | | |
2058 | 2058 | | |
| |||
2075 | 2075 | | |
2076 | 2076 | | |
2077 | 2077 | | |
2078 | | - | |
2079 | | - | |
| 2078 | + | |
| 2079 | + | |
2080 | 2080 | | |
2081 | 2081 | | |
2082 | 2082 | | |
| |||
2109 | 2109 | | |
2110 | 2110 | | |
2111 | 2111 | | |
2112 | | - | |
2113 | | - | |
| 2112 | + | |
| 2113 | + | |
2114 | 2114 | | |
2115 | 2115 | | |
2116 | 2116 | | |
| |||
2135 | 2135 | | |
2136 | 2136 | | |
2137 | 2137 | | |
2138 | | - | |
| 2138 | + | |
2139 | 2139 | | |
2140 | 2140 | | |
2141 | 2141 | | |
| |||
2168 | 2168 | | |
2169 | 2169 | | |
2170 | 2170 | | |
2171 | | - | |
| 2171 | + | |
2172 | 2172 | | |
2173 | 2173 | | |
2174 | 2174 | | |
| |||
2181 | 2181 | | |
2182 | 2182 | | |
2183 | 2183 | | |
| 2184 | + | |
| 2185 | + | |
| 2186 | + | |
| 2187 | + | |
2184 | 2188 | | |
2185 | 2189 | | |
2186 | 2190 | | |
2187 | 2191 | | |
2188 | 2192 | | |
2189 | 2193 | | |
2190 | | - | |
| 2194 | + | |
2191 | 2195 | | |
2192 | 2196 | | |
2193 | 2197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
| |||
96 | 99 | | |
97 | 100 | | |
98 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
99 | 108 | | |
100 | 109 | | |
101 | 110 | | |
| |||
2079 | 2088 | | |
2080 | 2089 | | |
2081 | 2090 | | |
2082 | | - | |
2083 | | - | |
2084 | | - | |
| 2091 | + | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + | |
| 2095 | + | |
| 2096 | + | |
2085 | 2097 | | |
2086 | 2098 | | |
2087 | 2099 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11140 | 11140 | | |
11141 | 11141 | | |
11142 | 11142 | | |
| 11143 | + | |
11143 | 11144 | | |
11144 | 11145 | | |
11145 | 11146 | | |
11146 | | - | |
| 11147 | + | |
| 11148 | + | |
| 11149 | + | |
| 11150 | + | |
| 11151 | + | |
11147 | 11152 | | |
11148 | 11153 | | |
11149 | 11154 | | |
| |||
12775 | 12780 | | |
12776 | 12781 | | |
12777 | 12782 | | |
| 12783 | + | |
12778 | 12784 | | |
12779 | 12785 | | |
12780 | 12786 | | |
| |||
12801 | 12807 | | |
12802 | 12808 | | |
12803 | 12809 | | |
12804 | | - | |
| 12810 | + | |
| 12811 | + | |
| 12812 | + | |
| 12813 | + | |
| 12814 | + | |
12805 | 12815 | | |
12806 | 12816 | | |
12807 | 12817 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
371 | | - | |
| 371 | + | |
372 | 372 | | |
| 373 | + | |
373 | 374 | | |
374 | 375 | | |
375 | 376 | | |
| |||
405 | 406 | | |
406 | 407 | | |
407 | 408 | | |
408 | | - | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
409 | 414 | | |
410 | 415 | | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
| 416 | + | |
415 | 417 | | |
416 | 418 | | |
417 | 419 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1690 | 1690 | | |
1691 | 1691 | | |
1692 | 1692 | | |
1693 | | - | |
| 1693 | + | |
1694 | 1694 | | |
1695 | 1695 | | |
1696 | 1696 | | |
| |||
1766 | 1766 | | |
1767 | 1767 | | |
1768 | 1768 | | |
1769 | | - | |
| 1769 | + | |
1770 | 1770 | | |
1771 | 1771 | | |
1772 | 1772 | | |
| |||
1841 | 1841 | | |
1842 | 1842 | | |
1843 | 1843 | | |
1844 | | - | |
1845 | | - | |
1846 | | - | |
1847 | | - | |
| 1844 | + | |
1848 | 1845 | | |
1849 | 1846 | | |
1850 | 1847 | | |
| |||
1859 | 1856 | | |
1860 | 1857 | | |
1861 | 1858 | | |
1862 | | - | |
1863 | | - | |
1864 | | - | |
1865 | | - | |
| 1859 | + | |
1866 | 1860 | | |
1867 | 1861 | | |
1868 | 1862 | | |
| |||
0 commit comments