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 1meHTd-00036w-1c for pgsql-novice@arkaria.postgresql.org; Sat, 23 Oct 2021 13:54:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1meHTZ-0003ai-Og for pgsql-novice@arkaria.postgresql.org; Sat, 23 Oct 2021 13:54:21 +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 1meHTZ-0003aY-Es for pgsql-novice@lists.postgresql.org; Sat, 23 Oct 2021 13:54:21 +0000 Received: from forward500o.mail.yandex.net ([2a02:6b8:0:1a2d::610]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1meHTR-0003i2-5R for pgsql-novice@lists.postgresql.org; Sat, 23 Oct 2021 13:54:20 +0000 Received: from iva3-509fc3649d15.qloud-c.yandex.net (iva3-509fc3649d15.qloud-c.yandex.net [IPv6:2a02:6b8:c0c:4982:0:640:509f:c364]) by forward500o.mail.yandex.net (Yandex) with ESMTP id 7169C941B24; Sat, 23 Oct 2021 16:54:08 +0300 (MSK) Received: from iva4-b3ebd202b141.qloud-c.yandex.net (2a02:6b8:c0c:4e8e:0:640:b3eb:d202 [2a02:6b8:c0c:4e8e:0:640:b3eb:d202]) by iva3-509fc3649d15.qloud-c.yandex.net (mxback/Yandex) with ESMTP id ilVgKhwbrC-s7EW44KL; Sat, 23 Oct 2021 16:54:08 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1634997248; bh=TdE6XaJHUQvRmhplJuZgjWImzx6K/ejKZjMXt4RzCUQ=; h=In-Reply-To:From:Date:References:To:Subject:Message-ID; b=FTpK+HX59L0MEEWF4anhz7u987lFetBov+aj5xsXRgH/vq+Dw5ML33CAwMMwOK2Ma dyAqSbP+Ocxy1+MdbVpAcnDl8MlnCMUdQ/eaj3fLHKJDVWsTFW6YvXATSGJHhVZioZ FbB7De8y2hVzVTYTcJTAWvQR1gJX22uK+N9OA29s= Authentication-Results: iva3-509fc3649d15.qloud-c.yandex.net; dkim=pass header.i=@yandex.ru Received: by iva4-b3ebd202b141.qloud-c.yandex.net (smtp/Yandex) with ESMTPS id ECS3n90ByA-s7NuWAWA; Sat, 23 Oct 2021 16:54:07 +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: Date: Sat, 23 Oct 2021 16:54:07 +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="------------2E1CA7044E5BC47996301EB8" 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. --------------2E1CA7044E5BC47996301EB8 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. > GENERATE_SERIES: select unnest(array[x, x]) x from generate_series(1, 5) x; RECURSIVE CTE: with recursive x as ( select 1 x union all select x + 1 from x where x < 5) select unnest(array[x, x]) x from x; --------------2E1CA7044E5BC47996301EB8 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.

GENERATE_SERIES: select unnest(array[x, x]) x from generate_series(1, 5) x;

RECURSIVE CTE: with recursive x as ( select 1 x union all select x + 1 from x where x < 5) select unnest(array[x, x]) x from x;

--------------2E1CA7044E5BC47996301EB8--