-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variable orderByHasOutputColumnRef is set to late, if ref has length 2, the return skips setting it to true #962
Comments
@oklemenz2 does this query throw a SQL error ? As this is the intended behavior when the order by clause references a column from the source and not a column from the output columns it is not required to have an additional wrapper as the alias |
Exactly this SQL is not valid and throws an error:
Why wrapping also this case for orderBy it works. We patched our version to continue... Order by should be
instead of
We now always apply wrapping for orderBy. |
I tried to reproduce the issue in one of our tests, but the SQL queries are running without errors and are producing the correct behavior. test('order by selected result column with join aliases', async () => {
const { Authors } = cds.entities('sap.capire.bookshop')
const res = await SELECT
.columns`ID,createdAt,books.price as price,books.genre.name as genre`
.from`${Authors} as Authors`
.where`Authors.ID in ${{ list: [{ val: 170 }, { val: 150 }] }} and books.ID = ${251} or Authors.ID in ${{ list: [{ val: 170 }, { val: 150 }] }} and books.ID = ${252}`
.orderBy`Authors.createdAt desc`
}) The produced working simple sql query SELECT
Authors.ID as "ID",
to_char(Authors.createdAt,'YYYY-MM-DD"T"HH24:MI:SS.FF3"Z"') as "createdAt",
TO_NVARCHAR(books.price) as "price",
genre.name as "genre"
FROM
sap_capire_bookshop_Authors as Authors
left JOIN sap_capire_bookshop_Books as books ON books.author_ID = Authors.ID
left JOIN sap_capire_bookshop_Genres as genre ON genre.ID = books.genre_ID
WHERE
Authors.ID in (SELECT * FROM JSON_TABLE(?, '$' COLUMNS("val" DOUBLE PATH '$.val')))
and books.ID = ?
or Authors.ID in (SELECT * FROM JSON_TABLE(?, '$' COLUMNS("val" DOUBLE PATH '$.val')))
and books.ID = ?
ORDER BY
Authors.createdAt DESC |
https://github.com/cap-js/cds-dbs/blob/f39097c0e991e7726960c6aa3bab6a81efe2669f/hana/lib/HANAService.js#L392C14-L392C15
The text was updated successfully, but these errors were encountered: