bitemyapp / bitemyapp/esqueleto
Database.Esqueleto.PostgreSQL.upsertBy syntax error in generated SQL
- Dominant language
- Haskell
- Stars
- 399
- Forks
- 107
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 1
Description
Error was found in esqueleto 3.5.3 from hackage. To reproduce, you need to apply expression similar to
```haskell
import qualified Database.Esqueleto.PostgreSQL as Psql
Psql.upsertBy
(UniqueUser email)
userData
[]
```
And then error will look like
```
uncaught exception: SomeAsyncException
ExceptionInLinkedThread ThreadId 3880 (SqlError {sqlState = "42601", sqlExecStatus = Fat
alError, sqlErrorMsg = "syntax error at or near \"WHERE\"", sqlErrorDetail = "", sqlErrorHint =
""})
```
Expected behaviour - atomic insert in case where Unique key was not used yet, and ignore (no update) in case Unique key has been already used.
There is a workaround to avoid such error and get expected behaviour - you need to do redundant update of Unique key like this:
```haskell
import qualified Database.Esqueleto.PostgreSQL as Psql
Psql.upsertBy
(UniqueUser email)
userData
[UserEmail =. val email]
```
But in my opinion it should work as expected without any workarounds.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with Database.Esqueleto.PostgreSQL.upsertBy and reproduce the reported call using an unused and an already-used UniqueUser key against PostgreSQL. Inspect the generated SQL around the WHERE clause; done means the call performs an atomic insert for a new key and ignores an existing key without requiring a redundant update.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell, postgresql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100