Is it possible to use esqueleto to create a query that returns a constant value? Like SELECT 1
for example.
Asked
Active
Viewed 134 times
1

snøreven
- 1,904
- 2
- 19
- 39
-
Try `select (return 1)` -- can't check it now, but it might work. – chi Jul 09 '16 at 11:04
-
@chi: unfortunately not: `No instance for (Database.Esqueleto.Internal.Sql.SqlSelect Int r0)` – snøreven Jul 09 '16 at 11:09
1 Answers
1
Try this:
import Database.Esqueleto
-- | We have to specialize `val` or else the type inferencer
-- will complain about the `Esqueleto` instance.
val_ :: Int -> SqlExpr (Value Int)
val_ = val
query :: SqlPersistT IO [Value Int]
query = select $ return (val_ 1)
@chi's comment was close, but the 1
needed to be lifted into a SqlExpr
. val
is written generically and depends on an Esqueleto
class instance. Normally the type inferencer would grab this as soon as you used from
and pulled in a SQL table, but since none of that is available here we have to specialize manually.
Overall a good example of how typeclasses can obfuscate meaning and force people to turn to documentation or forums.

hao
- 10,138
- 1
- 35
- 50