esqueleto
esqueleto copied to clipboard
Feature Request: Support for representing literal values as a Table
It would be amazing to have support for something like this:
WITH foo (col1, col2, col3) AS (
SELECT * FROM (
VALUES
(1, 2, 3),
(2, 3, 4)
) AS TMP
)
SELECT * FROM foo
I don't know the esqueleto codebase very well, but it seems that it could be added to the From GADT like so:
data From a where
Values
:: PersistEntity ent
=> [ent]
-> From (SqlExpr (Entity ent))
Table
:: PersistEntity ent
=> From (SqlExpr (Entity ent))
SubQuery
:: ( SqlSelect a r
, ToAlias a
, ToAliasReference a
)
=> SqlQuery a
-> From a
...
So this isn't a sql standard but rather postgresql specific as far as I can tell. I started work on a branch that eliminates the From GADT in favor of a typeclass. This would allow extensions of From to be made.in the backend specific modules.
Ahhhh, you are right, I only use postgresql so I just assumed other dbs had this capability. I would be happy to try and implement Values in the postgresql module once the migration to a typeclass has happened.