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 1tOaeB-007OcS-F9 for pgsql-sql@arkaria.postgresql.org; Fri, 20 Dec 2024 10:54:19 +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 1tOaeA-009c4S-G5 for pgsql-sql@arkaria.postgresql.org; Fri, 20 Dec 2024 10:54:18 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tOCeU-00A18s-ET for pgsql-sql@lists.postgresql.org; Thu, 19 Dec 2024 09:17:02 +0000 Received: from mail-oa1-x31.google.com ([2001:4860:4864:20::31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tOCeR-000M6u-I3 for pgsql-sql@lists.postgresql.org; Thu, 19 Dec 2024 09:17:01 +0000 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-268d0979e90so65224fac.3 for ; Thu, 19 Dec 2024 01:16:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734599818; x=1735204618; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=PngCJYyDnhk3X80VmcTAex0FMTjqIU860Irp6F0g6c0=; b=bsM3++PzaEvz1I5lWU66Hm61N8EJ/khhuf86BSwHpYj8RXjOv7I8Ch/qPguRd84J2f vH9J7qdU3P75BBPHchTcQwkinhd11eDdHSV6mQShRSBOVaEeemJOvBOwMv0ZUgl6oPPC Z//JGu2BiQXk4gVtYBYAWm6Sa27GCQIWlUHSo+npL3iN3sNxQB54D7TEZ7vsr02MWSMZ V5BCR4KH1DgWWGYX1Nl7gXj2oTcdZsayt9z63Z+jTUZQU0jy3OVDyaceEjNg2P20rGvt lgXfN3JeYli2tKTnsnaV01h72vOiHiKL3tOV1jeuV47Ue+klJycVPmolkHm5/DJzq5OW jsww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734599818; x=1735204618; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PngCJYyDnhk3X80VmcTAex0FMTjqIU860Irp6F0g6c0=; b=REibIcoSJIjeEquEjQEQf3sQw274AWofaGcFOqPR11hrQyQCGJsIaYRCWEWzTcQwoq Z3+qi4f+9EtP3AjlW29uLM6jTWpS50dsIpiOAPF03Qqeq7oNIgVdaLLhSoqdUdhsEvLl 4XIbt4U9WjsRrEH+BsweItz+b5cC8/j/cyZy3/O7Yl/EqLKtLe9bl08y/Zbm3U7AUe07 XfvJe+x38vw4gzh4cH0OFzhbDnzADako/2zN73NqnD6yAHsmmxi8Bp97HD3/pkLyiLef XrU5WEb0mRl2A3C7J0m2wrbLOr25rqYYu1M5iDtOnydwT2/WDRqqb3GFIM84F6iHABgH 9D+A== X-Gm-Message-State: AOJu0Ywktkwoe5jPyywrrE68QDocgLmls1qUKiyyMGLagNNkl6hI2ghK X0ObtHjhHOyjfxvBdlTODvTiA6aSC5RNa3CvBlVvZjFZQJfOynozGj+um7ImD6ybhEkSvaWXaY4 UoWatpIoBanBBlRVgBRmyo1KHCvY= X-Gm-Gg: ASbGncunBEdcMp1darF6E7HnPbMpeEu3PVbFrQsTY9wSUdVt6y91lWc/b7cEVRqX9Kh TuMr9c2Y+E9Lp8/u94FQHDVXE1Bzy0XhuzErcF0Ys X-Google-Smtp-Source: AGHT+IHbXQDPPYu6AnkdsHSg4+0q/y4fJaELeVAZjrQeKwvkB3/EkbWY0kyMmYz79fjwyBP6kMYB6Gd43ssJ9T7H2eo= X-Received: by 2002:a05:6870:610c:b0:29e:32e7:5f0d with SMTP id 586e51a60fabf-2a7b32d7a66mr1169563fac.10.1734599818249; Thu, 19 Dec 2024 01:16:58 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: sulfinu@gmail.com Date: Thu, 19 Dec 2024 11:16:47 +0200 Message-ID: Subject: Re: Abitity to identify the current iteration in a recursive SELECT (feature request) To: Greg Sabino Mullane Cc: pgsql-sql@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000fe8cd306299bfd5d" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000fe8cd306299bfd5d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Please read among your lines. =C3=8En mie., 18 dec. 2024 la 16:07, Greg Sabino Mullane a scris: > Do you mean something like "... WHERE pg_magic_iteration_number < 10"? > Looking at the source code, I don't see a trivial way to accomplish that. > Oh, I disagree, just told you that the iteration number is readily available in the field computed by the SEARCH BREADTH FIRST clause. > Maintaining the count as a column in your select is still the canonical > way. As someone who writes a lot of recursive CTEs (especially each > December!), I'm not sure how useful this feature would be, as the number = of > loops is rarely the criteria for ending the iterations. > I never said I use the iteration number to end the process, I need it to pick the right table to be joined. If the iteration number was stored in a *working table* column, I would be forced to perform a LATERAL join, which recomputes the *same joined table* again and again for every row in the working table. > > Certainly the best solution is to use pl/pgsql, which gets you iterative > loops, lots of introspection and ways to break out of the loop, and even > true recursion. > Thought about it, of course, but I'm pretty sure that plain JOINs are quicker than linear search loops written in pl/pgsql (remember I need to intersect an dynamic number of arrays) . --000000000000fe8cd306299bfd5d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Please read among your lines.

=C3=8En mie., 18 dec. 2024 la 16:07, Greg Sabino Mullane <htamfids@gmail.com> a scris:
Do you mean something like "... WHERE pg_magic_i= teration_number < 10"? Looking at the source code, I don't see = a trivial way to accomplish that.

Oh, I disagree, just told you that the iteration number is readily= available in the field computed by the SEARCH BREADTH FIRST clause.
=C2=A0
Maintaining=C2=A0the count as a column in your select is sti= ll the canonical way. As someone who writes a lot of recursive CTEs (especi= ally each December!), I'm not sure how useful this feature would be, as= the number of loops is rarely the criteria for ending the iterations.
=C2=A0
I never said I use the iter= ation number to end the process, I need it to pick the right table to be jo= ined. If the iteration number was stored in a working table column, = I would be forced to perform a LATERA= L join, which recomputes the same joined table again and agai= n for every row in the working table.
=C2=A0

Certainly the best solution is to use pl/pgsql, which gets= you iterative loops, lots of introspection=C2=A0and ways to break out of t= he loop, and even true recursion.

Thought about it, of course, but I'm pretty sure that plain JOINs a= re quicker than linear search loops written in pl/pgsql (remember I need to= intersect an dynamic number of arrays) .
--000000000000fe8cd306299bfd5d--