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 1meGmF-00012d-PQ for pgsql-novice@arkaria.postgresql.org; Sat, 23 Oct 2021 13:09:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1meGmE-00065O-M7 for pgsql-novice@arkaria.postgresql.org; Sat, 23 Oct 2021 13:09:34 +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 1meGmE-00065F-01 for pgsql-novice@lists.postgresql.org; Sat, 23 Oct 2021 13:09:34 +0000 Received: from resqmta-po-05v.sys.comcast.net ([2001:558:fe16:19:96:114:154:164]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1meGmB-0003PE-42 for pgsql-novice@lists.postgresql.org; Sat, 23 Oct 2021 13:09:32 +0000 Received: from resomta-po-05v.sys.comcast.net ([96.114.154.229]) by resqmta-po-05v.sys.comcast.net with ESMTP id eGhumrxyIoWleeGm9mj4CN; Sat, 23 Oct 2021 13:09:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=20190202a; t=1634994569; bh=7gv41l9MtUf4VqrjKwUgGILcqUg/h1pxCiQbQQyEBoI=; h=Received:Received:Date:From:To:Message-ID:Subject:MIME-Version: Content-Type; b=dpZKiLuXZCLMbH2OwlPGXgAwtp7Mhe+5NpTZc/btjUK9xjeGhATnv3kJW0Bx47qoh p8VfezlwvXbTyqIw2hRKc7/uxsKwvPBpFLz1Kp1z7uWjpy7GahT7CQZu14ylWOEnCH Jndz9GbQZ1wmo9P5EMi+RRtqhcnbkejkKdsPfNheanAj6KwrQhW2LqwWhvl94uoVvp C4qFkVLnm3yFbzZh5JRABloitd/SsKrzOE/hd9msoqY+ebvxmB8gYm1Tm6DA30Fvwm 4Bw12xHxBFJj8Faekl5YMZJpNk78JG2aOGJ57y5OZ/5Tg1QdypeQfrmpZ9lD5N08nL yyoaNQHVuR8Fw== Received: from oxapp-hoa-06o.email.comcast.net ([96.116.226.145]) by resomta-po-05v.sys.comcast.net with ESMTPS id eGm5mTNcHUQLZeGm5mwFKS; Sat, 23 Oct 2021 13:09:29 +0000 X-Xfinity-VAAS: gggruggvucftvghtrhhoucdtuddrgedvtddrvdeftddgheelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuvehomhgtrghsthdqtfgvshhipdfqfgfvpdfpqffurfetoffkrfenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepfffhvffkjghfufggtgfrkgfoihesrgdtsggsredtjeenucfhrhhomhepvffkofcuvefjkffnffcuoehtihhmrdgthhhilhgusegtohhmtggrshhtrdhnvghtqeenucggtffrrghtthgvrhhnpeffhffhhedvfefhledutefhtdelueehhfeugedtfedtteekffduffeuvdffgfejjeenucffohhmrghinhepphhrohhtohhnmhgrihhlrdgtohhmnecukfhppeeliedrudduiedrvddviedrudeghedpvdegrdeirddvfeehrddvgeegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehhvghlohepohigrghpphdqhhhorgdqtdeiohdrvghmrghilhdrtghomhgtrghsthdrnhgvthdpihhnvghtpeeliedrudduiedrvddviedrudeghedpmhgrihhlfhhrohhmpehtihhmrdgthhhilhgusegtohhmtggrshhtrdhnvghtpdhrtghpthhtohepshhqlhgpphgruggrfigrnhesphhrohhtohhnmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqnhhovhhitggvsehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrgh X-Xfinity-VMeta: sc=-100.00;st=legit Date: Sat, 23 Oct 2021 06:09:25 -0700 (PDT) From: TIM CHILD To: SQL Padawan , "pgsql-novice@lists.postgresql.org" Message-ID: <1340188717.307707.1634994565348@connect.xfinity.com> In-Reply-To: References: Subject: Re: Strange sequences - how to construct? MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_307706_46567926.1634994565340" X-Priority: 3 Importance: Normal X-Mailer: Open-Xchange Mailer v7.10.5-Rev21 X-Originating-IP: ::ffff:24.6.235.244 X-Originating-Client: open-xchange-appsuite List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------=_Part_307706_46567926.1634994565340 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Here is a way using multiple sequences: drop sequence if exists controller_sequence; drop sequence if exists odd_values; drop sequence if exists even_values; create sequence if not exists controller_sequence; create sequence if not exists odd_values start with 1; create sequence if not exists even_values start with 1; create function next_my_sequence() returns integer as $body$ declare choose integer; begin choose = nextval('controller_sequence'); if choose % 2 equals then return nextval('even_values'); else return nextval('odd_values'); end if; end; $body$ language plpgsql; -- example: get 5 sequences select next_my_sequence(), next_my_sequence(), next_my_sequence(), next_my_sequence(), next_my_sequence(); > On 10/22/2021 12:29 PM 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 https://protonmail.com/ Secure Email. > > ------=_Part_307706_46567926.1634994565340 MIME-Version: 1.0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit
Here is a way using multiple sequences:

drop sequence if exists controller_sequence;
drop sequence if exists odd_values;
drop sequence if exists even_values;
create sequence if not exists controller_sequence;
create sequence if not exists odd_values start with 1;
create sequence if not exists even_values start with 1;
create function next_my_sequence() returns integer as
$body$
declare
choose integer;
begin
choose = nextval('controller_sequence');
if choose % 2 equals then
return nextval('even_values');
else
return nextval('odd_values');
end if;
end;
$body$
language plpgsql;
-- example: get 5 sequences
select next_my_sequence(), next_my_sequence(), next_my_sequence(), next_my_sequence(), next_my_sequence();


On 10/22/2021 12:29 PM SQL Padawan <sql_padawan@protonmail.com> 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.

------=_Part_307706_46567926.1634994565340--