diff --git a/changelog.md b/changelog.md index a36dfe54d..9f6a79373 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,9 @@ +3.5.13.2 +======== +- @RikvanToor + - [#373](https://github.com/bitemyapp/esqueleto/pull/373) + - Fix name clashes when using CTEs multiple times + 3.5.13.1 ======== - @csamak diff --git a/esqueleto.cabal b/esqueleto.cabal index 5d2da3d39..262e92307 100644 --- a/esqueleto.cabal +++ b/esqueleto.cabal @@ -2,7 +2,7 @@ cabal-version: 1.12 name: esqueleto -version: 3.5.13.1 +version: 3.5.13.2 synopsis: Type-safe EDSL for SQL queries on persistent backends. description: @esqueleto@ is a bare bones, type-safe EDSL for SQL queries that works with unmodified @persistent@ SQL backends. Its language closely resembles SQL, so you don't have to learn new concepts, just new syntax, and it's fairly easy to predict the generated SQL and optimize it for your backend. Most kinds of errors committed when writing SQL are caught as compile-time errors---although it is possible to write type-checked @esqueleto@ queries that fail at runtime. . diff --git a/src/Database/Esqueleto/Experimental/From/CommonTableExpression.hs b/src/Database/Esqueleto/Experimental/From/CommonTableExpression.hs index a0d72b9f0..2a7898b97 100644 --- a/src/Database/Esqueleto/Experimental/From/CommonTableExpression.hs +++ b/src/Database/Esqueleto/Experimental/From/CommonTableExpression.hs @@ -53,7 +53,11 @@ with query = do let clause = CommonTableExpressionClause NormalCommonTableExpression ident (\info -> toRawSql SELECT info aliasedQuery) Q $ W.tell mempty{sdCteClause = [clause]} ref <- toAliasReference ident aliasedValue - pure $ From $ pure (ref, (\_ info -> (useIdent info ident, mempty))) + pure $ From $ do + newIdent <- newIdentFor (DBName "cte") + localRef <- toAliasReference newIdent ref + let makeLH info = useIdent info ident <> " AS " <> useIdent info newIdent + pure (localRef, (\_ info -> (makeLH info, mempty))) -- | @WITH@ @RECURSIVE@ allows one to make a recursive subquery, which can -- reference itself. Like @WITH@, this is supported in most modern SQL engines.