Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tOesr-007rWv-Lc for pgsql-sql@arkaria.postgresql.org; Fri, 20 Dec 2024 15:25:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tOesq-00CfBT-Pd for pgsql-sql@arkaria.postgresql.org; Fri, 20 Dec 2024 15:25:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tOesq-00CfBK-EQ for pgsql-sql@lists.postgresql.org; Fri, 20 Dec 2024 15:25:44 +0000 Received: from mout.gmx.net ([212.227.17.22]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tOesn-000lqK-0D for pgsql-sql@lists.postgresql.org; Fri, 20 Dec 2024 15:25:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1734708340; x=1735313140; i=shammat@gmx.net; bh=FfDJW5PpDyKe3hT56f57czSLtYSr1TYve3MJNQ6OWeI=; h=X-UI-Sender-Class:Message-ID:Date:MIME-Version:Subject:To: References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=jCRQ3v796vZRmOwwWTgl9HHX2aWoVaGXPi/Oz0iLGNAEOAIs+EZcCh2lMEdA+iQw gVf2UnwZjPlV+iypUAYhqEY/iXDolw6BRS/vFvP+HqC82+Ur9Ma49TFZQzY40SmIv Ud/FEEqTvZdSEvlHe80OZUiW41oVPdQyojt01GCz3iGm4NB+iHkGzoJVGp79jE26/ gBUQldt4ZINp9c16fhMadO8HURFiXscg8uFaALFHc56kUuAi0gKa8bTDQn6dFEL7n Uu6vKFZtVb+lEEehxOy5QkT6y3k3PCQhHx6OtMh0dB/LuyUQf7AlseawteBIqduI/ ssxix8c/gNAkr1hO8A== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.178.31] ([88.217.180.54]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MatRT-1u0BlH1mih-00dEoQ for ; Fri, 20 Dec 2024 16:25:40 +0100 Message-ID: <3926d507-2ef4-4b94-ba84-2dafd2e1110a@gmx.net> Date: Fri, 20 Dec 2024 16:25:39 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Abitity to identify the current iteration in a recursive SELECT (feature request) To: pgsql-sql@lists.postgresql.org References: Content-Language: de-DE, en-US From: shammat@gmx.net In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:0yc87t3eSdiPiL+mx8WHD2r1c+BVUe5uYTN6/ITIfGN/Ve7eJH6 OjMs926piWUXCkUdUCuhXD0jYpxf83TMCg0wvijLonVt9bRmwWSeshTi/al9Ap/di1vkrMC E6eYHwMSYqKUFHdEQ9RMG1dpkO9vFpiBpvaML+RRl0hLlsmDxMDny6JFLoMcHjEL6JVw1ib uTuyLcvLqUQZckknLjEWg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:1SVpaJrQyCk=;/5GTT+6RByUZJAGtv176puA/yX7 n8A+XqshMc1F3otHKPwF+lnK7sXPyTScp96oR1LPg1dsQ3R15qvAGl9snZW63aDCk36l21G9u aXvrs8ke1BfF7JPZk4x825a/w39bItF/Nfp1hJVTuh+l2lXr0CtwKv1AtOOKRGebwlegy70IQ 3HhpU7puDhuVopkvCUOFsTok3jgr+36doe4FSQnM1vsEw7GJkKuH7KfjiV3qb2LVHlzUP9sLx DXJk2LYWK5jKhtId0wQG3PJItGP4LQm1AYvFmV4vPCIFQ2D0S8rjHld9qsP3bz/u54MvMwv06 QlnLpUHE8kj57T66+BIfB1BRTqadiWjcZXSog9YPWIuB7U9Ly0rc/qZhny3LJAggny8JbBBLr D9xSgZFQClM/K8RshLEhJMFdvANOid4i4GNTLwCL1Pfrd0gNVEAj4p9Yv6DUKA3wbdx3+cOzb ZoxkV1G8Q3H2m6MzW8MItJx6JWeEhCsAgCVQ3glMcQVnGkfnVHB2HhYzbprCtDSTiVRSF53sn kwGUYjr3UbcH66rRUieEdKrysRXxNx1heZmX9CJ1XcpaEdb8kWQ6SFWI+l9rqXJJ0HeAv7Uy6 jhldfdEtyHAMEOAnA6OZyi50TARBgDKCmwJczGPXAv3kBSbdVEyrObwOBseuzXC/OM8duoec9 4gRTHPUSko2ODE+YKyG2hNEh9mnUcnZphC9sRffNhjypJ57R/S3uN0wBZn2evqrvkXcRxQBGr BRKcLyEVIMMD0AWHjuOoNFmePSxcxESW/z214b54YQi/JsgyipUGciYpKm1jNt8cSXSG+x3Va zCuQ/k4prdd2spWGwApGSxd2tsmnx/csaekigg4itAoPUX1OZVodmXNtyRqmv9uji27s9RLPz 97GDJTTTGOnpT7UY9kf0bE1AGYD3cakht4AnIh6hfvl/tHVPHVyu5LUMyEJLIsit0ce0dmw4R CBjJ+UbwVACHynoPjMMEbpVm5qtk2xmKo2dzK6yRxYf4uD51R6QBf7Cz2zoGspcEkNfH6F+y/ 7Ojqfn4MH8z6U/5ITiXOwxiUe09wacUuBYm6qx2hQap3yBCqqR3q7DfdXGfLAKsVAo6emPIoD hL+P0gJTFZPT51o1rE2MwuZ3Jq+IWI List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Am 16.12.24 um 11:21 schrieb sulfinu@gmail.com: > the algorithm present here queries-with.html#QUERIES-WITH-RECURSIVE> for the resolution of WITH > RECURSIVE queries is, broadly speaking, iterative, with the > iteration sequence number indicated in the first row item of the > field generated by the SEARCH BREADTH FIRST clause, > i.e. /0/, /1/, /2/ etc. > > Is there a way to obtain directly this iteration sequence number > within the SELECT statement following the UNION keyword in a > recursive construction? I know it can by obtained by maintaining its > value in a working table column, but that's suboptimal - I need it > as a "magic" variable, akin, for example, the excluded variable > available inside the ON CONFLICT DO UPDATE clause of an INSERT > statement. > I assume you don't want to do something like the following when you refer to "working table column"? with recursive cte as ( select ..., 1 as level from ... union all select ...., parent.level + 1 from ... join cte as parent on ... )