bitemyapp / bitemyapp/esqueleto

Typechecked Insertion combinators generate invalid query

Open
#91 1 comment 0 reactions 0 assignees View on GitHub
bug help wanted
Dominant language
Haskell
Stars
399
Forks
107
Avg merge
1d 17h
Merged PRs (30d)
1

Description

This code compiles:

```haskell
{-# 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:

```haskell
q = insertSelect $ from $ \t -> return (Table2 <# val 1 <&> (t ^. Table1Col1))
```
which generates

```
INSERT INTO `table2`(`col1`, `col2`)
SELECT ?, `table1`.`col1`
FROM `table1`
; [PersistInt64 1]
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.