Re: Strange sequences - how to construct? - Mailing list pgsql-novice

From TIM CHILD
Subject Re: Strange sequences - how to construct?
Date
Msg-id 1340188717.307707.1634994565348@connect.xfinity.com
Whole thread Raw
In response to Strange sequences - how to construct?  (SQL Padawan <sql_padawan@protonmail.com>)
List pgsql-novice
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.

pgsql-novice by date:

Previous
From: TIM CHILD
Date:
Subject: Re: Strange sequences - how to construct?
Next
From: Alexey M Boltenkov
Date:
Subject: Re: Strange sequences - how to construct?