esqueleto icon indicating copy to clipboard operation
esqueleto copied to clipboard

Feature Request: Support for representing literal values as a Table

Open JonathanLorimer opened this issue 5 years ago • 2 comments

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
    ...

JonathanLorimer avatar Nov 27 '20 22:11 JonathanLorimer

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.

belevy avatar Nov 29 '20 00:11 belevy

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.

JonathanLorimer avatar Nov 29 '20 17:11 JonathanLorimer