bitemyapp / esqueleto

New home of Esqueleto, please file issues so we can get things caught up!
BSD 3-Clause "New" or "Revised" License
370 stars 107 forks source link

Fix distinctOnOrderBy with nested expression #278

Closed NikitaRazmakhnin closed 2 years ago

NikitaRazmakhnin commented 2 years ago

Should solve https://github.com/bitemyapp/esqueleto/issues/277. Code assembling DISTINCT ON clause was stripping important part of important nested expressions. It worked well without nested expressions but with them it just cuts by spaces parts with arguments. So for example with COALESCE(val, ?) ASC it splits assembled expression into ["COALESCE(val,", "?)", "ASC"] which causes bad sql for some cases.

I am not sure it is a good solution because I actually don't know is it possible to have other expressions here or not? Please, let me know if you see any other possible issues with that fix. :)

A related test-case is added.

Before submitting your PR, check that you've:

After submitting your PR: