public inbox for [email protected]
help / color / mirror / Atom feedFrom: TIM CHILD <[email protected]>
To: SQL Padawan <[email protected]>
To: [email protected] <[email protected]>
Subject: Re: Strange sequences - how to construct?
Date: Sat, 23 Oct 2021 06:09:25 -0700 (PDT)
Message-ID: <[email protected]> (raw)
In-Reply-To: <tiUZZ67DYCE5aY4wDAfIXjzlghyf4ndcG2m7wWRd0Rq3rtyhd38iJ9fN2iG088MxWOQtEBlEbsLXzqq-RUYer6rXXfS67pjdwthg8YRIgQU=@protonmail.com>
References: <tiUZZ67DYCE5aY4wDAfIXjzlghyf4ndcG2m7wWRd0Rq3rtyhd38iJ9fN2iG088MxWOQtEBlEbsLXzqq-RUYer6rXXfS67pjdwthg8YRIgQU=@protonmail.com>
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 <[email protected]> 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.
>
>
view thread (6+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: Strange sequences - how to construct?
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox