bitemyapp/esqueleto
Auf GitHub ansehenTypechecked Insertion combinators generate invalid query
Open
#91 geöffnet am 29. Mai 2018
bughelp wanted
Repository-Metriken
- Stars
- (395 Stars)
- PR-Merge-Metriken
- (PR-Metriken ausstehend)
Beschreibung
This code compiles:
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Bug where
import qualified Database.Persist.MySQL as PMySQL
import Database.Persist.TH
import Database.Esqueleto
import Control.Monad.IO.Class
mkPersist sqlSettings [persistLowerCase|
Table1 sql=table1
col1 Int
Table2 sql=table2
col1 Int
col2 Int
|]
q :: MonadIO m => SqlWriteT m ()
q = insertSelect $ from $ \t -> return (Table2 1 <# (t ^. Table1Col1))
But generates an invalid query:
INSERT INTO `table2`(`col1`, `col2`)
SELECT `table1`.`col1`
FROM `table1`
; []
*** Exception: ERRException (ERR {errCode = 1136, errState = "21S01", errMsg = "Column count doesn't match value count at row 1"})
Changing it like this works:
q = insertSelect $ from $ \t -> return (Table2 <# val 1 <&> (t ^. Table1Col1))
which generates
INSERT INTO `table2`(`col1`, `col2`)
SELECT ?, `table1`.`col1`
FROM `table1`
; [PersistInt64 1]