@@ -1379,8 +1379,14 @@ typeForGraphRefRelationalExpr NotEquals{} = do
13791379typeForGraphRefRelationalExpr (Extend extendTupleExpr expr) = do
13801380 rel <- typeForGraphRefRelationalExpr expr
13811381 evalGraphRefRelationalExpr (Extend extendTupleExpr (ExistingRelation rel))
1382−typeForGraphRefRelationalExpr expr@With{} = do
1382+typeForGraphRefRelationalExpr expr@(With withs _) = do
13831383 let expr' = substituteWithNameMacros [] expr
1384+ checkMacroName (WithNameExpr macroName tid) = do
1385+ rvs <- relationVariables <$> gfDatabaseContextForMarker tid
1386+ case M.lookup macroName rvs of
1387+ Just _ -> lift $ except $ Left (RelVarAlreadyDefinedError macroName) --this error does not include the transaction marker, but should be good enough to identify the cause
1388+ Nothing -> pure ()
1389+ mapM checkMacroName (map fst withs)
13841390 typeForGraphRefRelationalExpr expr'
13851391
13861392evalGraphRefAttributeNames :: GraphRefAttributeNames -> GraphRefRelationalExpr -> GraphRefRelationalExprM (S.Set AttributeName)