Fix distinct query on postgres

This commit is contained in:
Ajay
2023-07-26 16:02:21 -04:00
parent d23e9b9940
commit f0b0217c78
3 changed files with 30 additions and 9 deletions

View File

@@ -72,6 +72,15 @@ export class Sqlite implements IDatabase {
}
private static processQuery(query: string): string {
if (query.includes("DISTINCT ON")) {
const column = query.match(/DISTINCT ON \((.*)\) (.*)/)[1];
query = query.replace(/DISTINCT ON \((.*)\)/g, "");
const parts = query.split("ORDER BY");
query = `${parts[0]} GROUP BY ${column} ORDER BY ${parts[1]}`;
}
return query.replace(/ ~\* /g, " REGEXP ");
}