In non generic targets the extra ORDER BY section is added in the end of the output.
In my input I don't specify sorting and I don't need it.
And there is a tracks.name field from the tracks table in this section, which is not presented in FROM section.
It produces the error:
Reproduced in the website playground.
PRQL input
prql target:sql.postgres
from tracks
group media_type_id(
sort name
take 1
)
join media_types (== media_type_id)
select {
tracks.track_id,
media_types.name
}
SQL output
WITH table_0 AS (
SELECT
DISTINCT ON (media_type_id) track_id,
media_type_id,
name
FROM
tracks
ORDER BY
media_type_id,
name
)
SELECT
table_0.track_id,
media_types.name
FROM
table_0
JOIN media_types ON table_0.media_type_id = media_types.media_type_id
ORDER BY
table_0.media_type_id,
tracks.name
Expected SQL output
WITH table_0 AS (
SELECT
DISTINCT ON (media_type_id) track_id,
media_type_id,
name
FROM
tracks
ORDER BY
media_type_id,
name
)
SELECT
table_0.track_id,
media_types.name
FROM
table_0
JOIN media_types ON table_0.media_type_id = media_types.media_type_id
What happened?
In non generic targets the extra ORDER BY section is added in the end of the output. In my input I don't specify sorting and I don't need it.
And there is a tracks.name field from the tracks table in this section, which is not presented in FROM section. It produces the error:![image](https://github.com/PRQL/prql/assets/118341934/495a4321-3d71-4fa7-9465-e14f660cf4a3)
Reproduced in the website playground.
PRQL input
SQL output
Expected SQL output
MVCE confirmation
Anything else?
No response