Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Esqueleto: How can I delete an item using a join

Is the following query possible using esqueleto?

DELETE Table1
FROM Table1
INNER JOIN Table2 ON Table1.ID = Table2.ItemID

I've tried:

delete $ 
  from $ \(table1 `InnerJoin` table2) -> 
    on (table1 ^. Table1ID  ==. table2 ^. Table2ItemID)

which, oddly enough, generated one of the only runtime errors I've ever seen in Haskell

ERROR:  syntax error at or near "INNER"
LINE 2: FROM "table1" INNER JOIN "table2" ON "tab...

(basically, it was unhappy that the DELETE was missing the "table1")

I've also tried adding a return value to the monad, which, like with select might add that missing value. But this fails because delete requires a monad of type m ().

Is it possible that this is just missing from Esqueleto?

like image 736
jamshidh Avatar asked Sep 29 '15 03:09

jamshidh


1 Answers

I think it is very late to answer this question but you can use EXISTS

DELETE Table1
WHERE EXISTS (SELECT * FROM Table2 WHERE Table1.ID = Table2.ItemID)
like image 194
iman kazemi Avatar answered Oct 10 '22 11:10

iman kazemi