{"action":"created","issue":{"url":"https://api.github.com/repos/tomjaguarpaw/haskell-opaleye/issues/58","labels_url":"https://api.github.com/repos/tomjaguarpaw/haskell-opaleye/issues/58/labels{/name}","comments_url":"https://api.github.com/repos/tomjaguarpaw/haskell-opaleye/issues/58/comments","events_url":"https://api.github.com/repos/tomjaguarpaw/haskell-opaleye/issues/58/events","html_url":"https://github.com/tomjaguarpaw/haskell-opaleye/pull/58","id":92038101,"number":58,"title":"Adding support for WITH RECURSIVE.","user":{"login":"hesselink","id":75477,"avatar_url":"https://avatars.githubusercontent.com/u/75477?v=3","gravatar_id":"","url":"https://api.github.com/users/hesselink","html_url":"https://github.com/hesselink","followers_url":"https://api.github.com/users/hesselink/followers","following_url":"https://api.github.com/users/hesselink/following{/other_user}","gists_url":"https://api.github.com/users/hesselink/gists{/gist_id}","starred_url":"https://api.github.com/users/hesselink/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hesselink/subscriptions","organizations_url":"https://api.github.com/users/hesselink/orgs","repos_url":"https://api.github.com/users/hesselink/repos","events_url":"https://api.github.com/users/hesselink/events{/privacy}","received_events_url":"https://api.github.com/users/hesselink/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":17,"created_at":"2015-06-30T09:29:26Z","updated_at":"2015-07-06T21:32:05Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/tomjaguarpaw/haskell-opaleye/pulls/58","html_url":"https://github.com/tomjaguarpaw/haskell-opaleye/pull/58","diff_url":"https://github.com/tomjaguarpaw/haskell-opaleye/pull/58.diff","patch_url":"https://github.com/tomjaguarpaw/haskell-opaleye/pull/58.patch"},"body":"This isn't done, but I'd like some feedback. I've got most of the\nplumbing in place, but there are some issues. One is that I need to\nadd the table alias introduced by WITH RECURSIVE to the second\n(recursive) case. I've done this now in\nOpaleye.Internal.Sql.withRecursive, but I feel it's not ideal. It also\ndoesn't quite work, since it generates something like this:\n\n``` sql\nSELECT \"id0_2\" as result1_4,\n       \"name1_2\" as result2_4,\n       \"subpart2_2\" as result3_4\nFROM (SELECT *\n      FROM (WITH RECURSIVE \"with_recursive_result_3\" AS\n            (SELECT *\n             FROM (SELECT \"id\" as id0_1,\n                          \"name\" as name1_1,\n                          \"subpart\" as subpart2_1\n                   FROM \"parts\" as T1) as T1\n             UNION ALL\n             SELECT *\n             FROM \"with_recursive_result_3\" as T1,\n                  (SELECT \"id\" as id0_2,\n                          \"name\" as name1_2,\n                          \"subpart\" as subpart2_2\n                   FROM \"parts\" as T1) as T2\n             WHERE ((\"id0_1\") = (\"subpart2_2\")))\n            SELECT * FROM \"with_recursive_result_3\") as T1) as T1\n```\n\nNotice that the second, recursive query adds the recursive table, but\ndoes a 'SELECT *' outside of that, causing it to select more columns\nthan is wanted. I could either try to not select `*` but the right\ncolumns, or try to push the recursive table a bit further in (but how\nfar?).\n\nAny advice, pointers and answers to my questions appreciated :)"},"comment":{"url":"https://api.github.com/repos/tomjaguarpaw/haskell-opaleye/issues/comments/119003629","html_url":"https://github.com/tomjaguarpaw/haskell-opaleye/pull/58#issuecomment-119003629","issue_url":"https://api.github.com/repos/tomjaguarpaw/haskell-opaleye/issues/58","id":119003629,"user":{"login":"tomjaguarpaw","id":1951567,"avatar_url":"https://avatars.githubusercontent.com/u/1951567?v=3","gravatar_id":"","url":"https://api.github.com/users/tomjaguarpaw","html_url":"https://github.com/tomjaguarpaw","followers_url":"https://api.github.com/users/tomjaguarpaw/followers","following_url":"https://api.github.com/users/tomjaguarpaw/following{/other_user}","gists_url":"https://api.github.com/users/tomjaguarpaw/gists{/gist_id}","starred_url":"https://api.github.com/users/tomjaguarpaw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomjaguarpaw/subscriptions","organizations_url":"https://api.github.com/users/tomjaguarpaw/orgs","repos_url":"https://api.github.com/users/tomjaguarpaw/repos","events_url":"https://api.github.com/users/tomjaguarpaw/events{/privacy}","received_events_url":"https://api.github.com/users/tomjaguarpaw/received_events","type":"User","site_admin":false},"created_at":"2015-07-06T21:32:05Z","updated_at":"2015-07-06T21:32:05Z","body":"Cool!  It'll be a few  days before I can look at this properly.\r\n\r\n> I do a runUnpackspec twice in withRecursive: once to get the column names from the recursive query, and again to get the (fresh) column names to use for the total recursive query. Is there a simpler way?\r\n\r\nYou can come up with an `Applicative` (`Sum f g a = Sum (f a) (g a)` would do) that does both things that you want in one go, but I probably wouldn't bother.\r\n"}}