khibino / haskell-relational-record

This repository includes a joined query generator based on typefull relational algebra, and mapping tools between SQL values list and Haskell record type.
233 stars 36 forks source link

DELETE command with alias is invalid SQL syntax for MySQL #77

Open CYBAI opened 4 years ago

CYBAI commented 4 years ago

First of all, thanks for building this awesome library for generating type safe SQL queries.

While using this lib to build some queries, I found this issue for DELETE command.

https://github.com/khibino/haskell-relational-record/blob/070fc1ec100f23255adc7c19d829fcc58a3debb2/relational-query/test/sqlsEq.hs#L773-L777

Like the raw SQL command written in test of relational-query, currently, HRR will generate delete command with alias which is invalid syntax for MySQL.

Ex.

DELETE FROM table T0 WHERE T0.field = 'value';

There might be two solutions to fix this:

  1. Don't use alias for DELETE

DELETE FROM table WHERE field = 'value';

  1. Declare alias after DELETE would be valid syntax

(Edited: it's very sad this one will be invalid syntax for PostgreSQL 😢 )

DELETE T0 FROM table AS T0 WHERE T0.field = 'value';

As the second one is invalid for PostgreSQL, maybe we will need to fix this by the first solution 🤔 ?

@khibino WDYT? Thank you!