{"id":1169,"date":"2023-03-04T19:33:00","date_gmt":"2023-03-04T19:33:00","guid":{"rendered":"https:\/\/kpwalters.com\/?page_id=1169"},"modified":"2023-03-05T04:37:53","modified_gmt":"2023-03-05T04:37:53","slug":"simple-recursive-cte","status":"publish","type":"page","link":"https:\/\/kpwalters.com\/index.php\/data-analyst\/recursive-cte-project\/simple-recursive-cte\/","title":{"rendered":"Simple recursive CTE"},"content":{"rendered":"\n<div class=\"wp-block-uagb-container uagb-block-a9084b5f alignfull uagb-is-root-container\">\n<div class=\"wp-block-uagb-advanced-heading uagb-block-ef75e14a\"><h5 class=\"uagb-heading-text\">Simple recursive common table expression (CTE)<\/h5><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-uagb-container uagb-block-a33d0142 alignfull uagb-is-root-container\"><div class=\"uagb-container-inner-blocks-wrap\">\n<div class=\"wp-block-uagb-container uagb-block-08545dd4\"><\/div>\n\n\n\n<div class=\"wp-block-uagb-container uagb-block-6aae74e6\">\n<pre class=\"wp-block-code\"><code>-- ****************************************************************************\n-- This is a very rudimentary recursive common table expression (CTE). By \n-- modifying pieces of it, one can get a sense as to how a recursive CTE works.\n-- ****************************************************************************\nWITH RECURSIVE \"t\" AS \n\t(\n\t\t-- The top part of the UNION query sets the structure of the\n\t\t-- query.\n\t\tSELECT\n\t\t\t1 AS \"counter\"\n\t\t\t, CHR( 65 ) AS \"extra\"\n\t\t\t, CHR( 65 ) AS \"example\"\n\n\t\t-- The second half of the UNION query must include UNION ALL. \n\t\t-- It must include the CTE in the FROM clause. And it MUST have \n\t\t-- some kind of WHERE clause that will terminate the recursion.\n\t\tUNION ALL\n\t\tSELECT \n\t\t\tcounter + 1 AS \"counter\"\n\t\t\t, CHR( 65 + counter ) AS \"extra\"\n\t\t\t, example ||  CHR( 65 + counter ) AS \"example\"\n\t\tFROM t \n\t\tWHERE counter &lt; 4\n\t)\n\nSELECT \n\tcounter\n\t, extra\n\t, example\nFROM t\n;<\/code><\/pre>\n<\/div>\n\n\n\n<div class=\"wp-block-uagb-container uagb-block-8703fb4d\"><\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Simple recursive common table expression (CTE)<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":979,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"page-builder","ast-global-header-display":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"disabled","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"enabled","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","footnotes":""},"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"kevin.p.walters@live.com","author_link":"https:\/\/kpwalters.com\/index.php\/author\/kevin-p-walterslive-com\/"},"uagb_comment_info":0,"uagb_excerpt":"Simple recursive common table expression (CTE)","_links":{"self":[{"href":"https:\/\/kpwalters.com\/index.php\/wp-json\/wp\/v2\/pages\/1169"}],"collection":[{"href":"https:\/\/kpwalters.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/kpwalters.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/kpwalters.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kpwalters.com\/index.php\/wp-json\/wp\/v2\/comments?post=1169"}],"version-history":[{"count":7,"href":"https:\/\/kpwalters.com\/index.php\/wp-json\/wp\/v2\/pages\/1169\/revisions"}],"predecessor-version":[{"id":1406,"href":"https:\/\/kpwalters.com\/index.php\/wp-json\/wp\/v2\/pages\/1169\/revisions\/1406"}],"up":[{"embeddable":true,"href":"https:\/\/kpwalters.com\/index.php\/wp-json\/wp\/v2\/pages\/979"}],"wp:attachment":[{"href":"https:\/\/kpwalters.com\/index.php\/wp-json\/wp\/v2\/media?parent=1169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}