Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1meHYV-0003LA-E1 for pgsql-novice@arkaria.postgresql.org; Sat, 23 Oct 2021 13:59:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1meHYU-0006ul-Br for pgsql-novice@arkaria.postgresql.org; Sat, 23 Oct 2021 13:59:26 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1meHYU-0006ub-4E for pgsql-novice@lists.postgresql.org; Sat, 23 Oct 2021 13:59:26 +0000 Received: from forward500o.mail.yandex.net ([37.140.190.195]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1meHYQ-0003qm-55 for pgsql-novice@lists.postgresql.org; Sat, 23 Oct 2021 13:59:25 +0000 Received: from vla3-ceb7ce11bd61.qloud-c.yandex.net (vla3-ceb7ce11bd61.qloud-c.yandex.net [IPv6:2a02:6b8:c15:341d:0:640:ceb7:ce11]) by forward500o.mail.yandex.net (Yandex) with ESMTP id 1BE0C941C92; Sat, 23 Oct 2021 16:59:20 +0300 (MSK) Received: from vla5-445dc1c4c112.qloud-c.yandex.net (2a02:6b8:c18:3609:0:640:445d:c1c4 [2a02:6b8:c18:3609:0:640:445d:c1c4]) by vla3-ceb7ce11bd61.qloud-c.yandex.net (mxback/Yandex) with ESMTP id QqLDn9XdZb-xJFmjLLp; Sat, 23 Oct 2021 16:59:20 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1634997560; bh=IKocIGBEVSE2wRABzladRFoMjpoXQkH2ZyBFhYn5gXI=; h=In-Reply-To:From:Date:References:To:Subject:Message-ID; b=dt0OXMfo5wfufUGFGUP0r+O31VG+fa2a4q7FG7P6ycXj3E4vwirY1jlbMRT4G9R91 +MG81ATKnkGtyYm6D9UZx5VglYli/1rH42RWeGhGRVuQ4cucdVn07o5Zu2WEqi+fwK +RtL81d8nz6rvenCUIkxWJKeQUBtXLIBbY89z3RI= Authentication-Results: vla3-ceb7ce11bd61.qloud-c.yandex.net; dkim=pass header.i=@yandex.ru Received: by vla5-445dc1c4c112.qloud-c.yandex.net (smtp/Yandex) with ESMTPS id KWhcibYql4-xJ14wlLw; Sat, 23 Oct 2021 16:59:19 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) X-Yandex-Fwd: 2 Subject: Re: Strange sequences - how to construct? To: SQL Padawan , "pgsql-novice@lists.postgresql.org" References: From: Alexey M Boltenkov Message-ID: <6b774981-3126-0606-5a17-59fb125a213c@yandex.ru> Date: Sat, 23 Oct 2021 16:59:19 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------4D07F1A1073312781FA0B274" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------4D07F1A1073312781FA0B274 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 10/22/21 22:29, SQL Padawan wrote: > > Good afternoon to everybody. > > I wish to construct some weird sequences. > > 1 > 1 > 2 > 2 > &c. > > and with  3 ones, 4 ones... &c. > > Now, I know how to do a simple > 1 > 2 > 3 > 4 > > using both GENERATE_SERIES and using a RECURSIVE CTE. > > What I would like is to be able to construct my specified sequences > using *_both_* GENERATE_SERIES *_and_* RECURSIVE CTEs. > > Regards, > > SQL Padawan! > > > > > Sent with ProtonMail Secure Email. > Or may be you want something strange? *_both_* GENERATE_SERIES *_and_* RECURSIVE CTEs: with recursive x as ( select generate_series(1, 5) x union all select x + 1 from x where x = x - 1) select unnest(array[x, x]) x from x; --------------4D07F1A1073312781FA0B274 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
On 10/22/21 22:29, SQL Padawan wrote:

Good afternoon to everybody.

I wish to construct some weird sequences.

1
1
2
2
&c.

and with  3 ones, 4 ones... &c.

Now, I know how to do a simple
1
2
3
4

using both GENERATE_SERIES and using a RECURSIVE CTE.

What I would like is to be able to construct my specified sequences using *_both_* GENERATE_SERIES *_and_* RECURSIVE CTEs.

Regards,

SQL Padawan!




Sent with ProtonMail Secure Email.

Or may be you want something strange?

*_both_* GENERATE_SERIES *_and_* RECURSIVE CTEs: with recursive x as ( select generate_series(1, 5) x union all select x + 1 from x where x = x - 1) select unnest(array[x, x]) x from x;

--------------4D07F1A1073312781FA0B274--